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
This commit is contained in:
parent
c13901f4c8
commit
82e2725154
|
@ -777,13 +777,17 @@ export function getFactoryOf<T>(type: Type<any>): ((type?: Type<T>) => T)|null {
|
|||
}
|
||||
|
||||
export function getInheritedFactory<T>(type: Type<any>): (type: Type<T>) => T {
|
||||
debugger;
|
||||
const proto = Object.getPrototypeOf(type.prototype).constructor as Type<any>;
|
||||
const factory = getFactoryOf<T>(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();
|
||||
}
|
||||
}
|
||||
|
||||
class TemplateRef<T> implements viewEngine.TemplateRef<T> {
|
||||
|
|
Loading…
Reference in New Issue