refactor(ivy): fix type of factory functions to allow explicit types (#30855)
Factory functions written by the compiler optionally allow an explicit type to be passed. If called with this type, an instance of the given type will be created instead of the type for which the factory was generated. This is used to power inheritance of Angular types, as if the constructor of a class is inherited from its superclass, then the factory function of the superclass must be used (it has all the DI info) to construct an instance of the derived class. This commit adjusts typings in a few places to allow factory functions to be called with this extra type parameter. PR Close #30855
This commit is contained in:

committed by
Andrew Kushnir

parent
b2937b16c3
commit
0ee09cdd7e
@ -47,7 +47,7 @@ export interface ɵɵInjectableDef<T> {
|
||||
/**
|
||||
* Factory method to execute to create an instance of the injectable.
|
||||
*/
|
||||
factory: () => T;
|
||||
factory: (t?: Type<any>) => T;
|
||||
|
||||
/**
|
||||
* In a case of no explicit injector, a location where the instance of the injectable is stored.
|
||||
|
@ -24,7 +24,7 @@ export const angularCoreDiEnv: {[name: string]: Function} = {
|
||||
'ɵɵgetFactoryOf': getFactoryOf,
|
||||
};
|
||||
|
||||
function getFactoryOf<T>(type: Type<any>): ((type: Type<T>| null) => T)|null {
|
||||
function getFactoryOf<T>(type: Type<any>): ((type?: Type<T>) => T)|null {
|
||||
const typeAny = type as any;
|
||||
const def = getInjectableDef<T>(typeAny) || getInjectorDef<T>(typeAny);
|
||||
if (!def || def.factory === undefined) {
|
||||
|
Reference in New Issue
Block a user