forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefinition_factory.ts
More file actions
37 lines (33 loc) · 1.24 KB
/
definition_factory.ts
File metadata and controls
37 lines (33 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import {Type} from '../interface/type';
import {stringify} from '../util/stringify';
import {NG_FACTORY_DEF} from './fields';
/**
* Definition of what a factory function should look like.
*/
export type FactoryFn<T> = {
/**
* Subclasses without an explicit constructor call through to the factory of their base
* definition, providing it with their own constructor to instantiate.
*/
<U extends T>(t?: Type<U>): U;
/**
* If no constructor to instantiate is provided, an instance of type T itself is created.
*/
(t?: undefined): T;
};
export function getFactoryDef<T>(type: any, throwNotFound: true): FactoryFn<T>;
export function getFactoryDef<T>(type: any): FactoryFn<T> | null;
export function getFactoryDef<T>(type: any, throwNotFound?: boolean): FactoryFn<T> | null {
const hasFactoryDef = type.hasOwnProperty(NG_FACTORY_DEF);
if (!hasFactoryDef && throwNotFound === true && ngDevMode) {
throw new Error(`Type ${stringify(type)} does not have 'ɵfac' property.`);
}
return hasFactoryDef ? type[NG_FACTORY_DEF] : null;
}