From 82e2725154e0fe42b475c4c458241b5f46545a46 Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Fri, 10 Aug 2018 11:15:59 +0100 Subject: [PATCH] fix(ivy): handle the case where no base factory is found (#25425) When an Angular decorated class is inherited, it might be the case that the entire inheritance chain actually has no constructor defined. In that event, a factory which simply instantiates the type without any arguments should be used. PR Close #25425 --- packages/core/src/render3/di.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core/src/render3/di.ts b/packages/core/src/render3/di.ts index a539e0972b..28eced1bda 100644 --- a/packages/core/src/render3/di.ts +++ b/packages/core/src/render3/di.ts @@ -777,13 +777,17 @@ export function getFactoryOf(type: Type): ((type?: Type) => T)|null { } export function getInheritedFactory(type: Type): (type: Type) => T { - debugger; const proto = Object.getPrototypeOf(type.prototype).constructor as Type; const factory = getFactoryOf(proto); - if (factory === null) { - throw new Error(`Type ${proto.name} does not support inheritance`); + if (factory !== null) { + return factory; + } else { + // There is no factory defined. Either this was improper usage of inheritance + // (no Angular decorator on the superclass) or there is no constructor at all + // in the inheritance chain. Since the two cases cannot be distinguished, the + // latter has to be assumed. + return (t) => new t(); } - return factory; } class TemplateRef implements viewEngine.TemplateRef {