refactor(core): add single type for injector token (#41580)

Currently we have a lot of places where we repeat the type `Type<T>|AbstractType<T>|InjectionToken<T>` which makes it cumbersome to add another type or to type something else with the same signature.

These changes add a new type that can be used instead.

Fixes #39792.

PR Close #41580
This commit is contained in:
Kristiyan Kostadinov 2021-04-12 17:32:10 +02:00 committed by Jessica Janiuk
parent 3ceb3dea67
commit de4fafb818
20 changed files with 138 additions and 170 deletions

View File

@ -159,11 +159,11 @@ export declare interface ConstructorSansProvider {
export declare type ContentChild = Query; export declare type ContentChild = Query;
export declare interface ContentChildDecorator { export declare interface ContentChildDecorator {
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { (selector: ProviderToken<unknown> | Function | string, opts?: {
read?: any; read?: any;
static?: boolean; static?: boolean;
}): any; }): any;
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { new (selector: ProviderToken<unknown> | Function | string, opts?: {
read?: any; read?: any;
static?: boolean; static?: boolean;
}): ContentChild; }): ContentChild;
@ -172,12 +172,12 @@ export declare interface ContentChildDecorator {
export declare type ContentChildren = Query; export declare type ContentChildren = Query;
export declare interface ContentChildrenDecorator { export declare interface ContentChildrenDecorator {
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { (selector: ProviderToken<unknown> | Function | string, opts?: {
descendants?: boolean; descendants?: boolean;
emitDistinctChangesOnly?: boolean; emitDistinctChangesOnly?: boolean;
read?: any; read?: any;
}): any; }): any;
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { new (selector: ProviderToken<unknown> | Function | string, opts?: {
descendants?: boolean; descendants?: boolean;
emitDistinctChangesOnly?: boolean; emitDistinctChangesOnly?: boolean;
read?: any; read?: any;
@ -448,7 +448,7 @@ export declare class InjectionToken<T> {
} }
export declare abstract class Injector { export declare abstract class Injector {
abstract get<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T; abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
/** @deprecated */ abstract get(token: any, notFoundValue?: any): any; /** @deprecated */ abstract get(token: any, notFoundValue?: any): any;
static NULL: Injector; static NULL: Injector;
static THROW_IF_NOT_FOUND: {}; static THROW_IF_NOT_FOUND: {};
@ -680,8 +680,8 @@ export declare function ɵɵdefineInjectable<T>(opts: {
}): unknown; }): unknown;
/** @codeGenApi */ /** @codeGenApi */
export declare function ɵɵinject<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>): T; export declare function ɵɵinject<T>(token: ProviderToken<T>): T;
export declare function ɵɵinject<T>(token: Type<T> | AbstractType<T> | InjectionToken<T>, flags?: InjectFlags): T | null; export declare function ɵɵinject<T>(token: ProviderToken<T>, flags?: InjectFlags): T | null;
/** @codeGenApi */ /** @codeGenApi */
export declare function ɵɵinjectAttribute(attrNameToInject: string): string | null; export declare function ɵɵinjectAttribute(attrNameToInject: string): string | null;
@ -725,6 +725,8 @@ export declare interface Predicate<T> {
export declare type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | any[]; export declare type Provider = TypeProvider | ValueProvider | ClassProvider | ConstructorProvider | ExistingProvider | FactoryProvider | any[];
export declare type ProviderToken<T> = Type<T> | AbstractType<T> | InjectionToken<T>;
export declare interface Query { export declare interface Query {
descendants: boolean; descendants: boolean;
emitDistinctChangesOnly: boolean; emitDistinctChangesOnly: boolean;
@ -989,11 +991,11 @@ export declare const VERSION: Version;
export declare type ViewChild = Query; export declare type ViewChild = Query;
export declare interface ViewChildDecorator { export declare interface ViewChildDecorator {
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { (selector: ProviderToken<unknown> | Function | string, opts?: {
read?: any; read?: any;
static?: boolean; static?: boolean;
}): any; }): any;
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { new (selector: ProviderToken<unknown> | Function | string, opts?: {
read?: any; read?: any;
static?: boolean; static?: boolean;
}): ViewChild; }): ViewChild;
@ -1002,11 +1004,11 @@ export declare interface ViewChildDecorator {
export declare type ViewChildren = Query; export declare type ViewChildren = Query;
export declare interface ViewChildrenDecorator { export declare interface ViewChildrenDecorator {
(selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { (selector: ProviderToken<unknown> | Function | string, opts?: {
read?: any; read?: any;
emitDistinctChangesOnly?: boolean; emitDistinctChangesOnly?: boolean;
}): any; }): any;
new (selector: Type<any> | InjectionToken<unknown> | Function | string, opts?: { new (selector: ProviderToken<unknown> | Function | string, opts?: {
read?: any; read?: any;
emitDistinctChangesOnly?: boolean; emitDistinctChangesOnly?: boolean;
}): ViewChildren; }): ViewChildren;

View File

@ -62,11 +62,11 @@ export declare interface TestBed {
configureTestingModule(moduleDef: TestModuleMetadata): void; configureTestingModule(moduleDef: TestModuleMetadata): void;
createComponent<T>(component: Type<T>): ComponentFixture<T>; createComponent<T>(component: Type<T>): ComponentFixture<T>;
execute(tokens: any[], fn: Function, context?: any): any; execute(tokens: any[], fn: Function, context?: any): any;
/** @deprecated */ get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; /** @deprecated */ get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated */ get(token: any, notFoundValue?: any): any; /** @deprecated */ get(token: any, notFoundValue?: any): any;
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void; initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): void;
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T | null; inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void; overrideComponent(component: Type<any>, override: MetadataOverride<Component>): void;
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void; overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): void;
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void; overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): void;
@ -99,11 +99,11 @@ export declare interface TestBedStatic {
}): TestBedStatic; }): TestBedStatic;
configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic; configureTestingModule(moduleDef: TestModuleMetadata): TestBedStatic;
createComponent<T>(component: Type<T>): ComponentFixture<T>; createComponent<T>(component: Type<T>): ComponentFixture<T>;
/** @deprecated */ get<T>(token: Type<T> | InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; /** @deprecated */ get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated */ get(token: any, notFoundValue?: any): any; /** @deprecated */ get(token: any, notFoundValue?: any): any;
initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed; initTestEnvironment(ngModule: Type<any> | Type<any>[], platform: PlatformRef, aotSummaries?: () => any[]): TestBed;
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
inject<T>(token: Type<T> | InjectionToken<T> | AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T | null; inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T | null;
overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic; overrideComponent(component: Type<any>, override: MetadataOverride<Component>): TestBedStatic;
overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic; overrideDirective(directive: Type<any>, override: MetadataOverride<Directive>): TestBedStatic;
overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic; overrideModule(ngModule: Type<any>, override: MetadataOverride<NgModule>): TestBedStatic;

View File

@ -18,6 +18,7 @@ export {ɵɵdefineInjectable, defineInjectable, ɵɵdefineInjector, InjectableTy
export {forwardRef, resolveForwardRef, ForwardRefFn} from './forward_ref'; export {forwardRef, resolveForwardRef, ForwardRefFn} from './forward_ref';
export {Injectable, InjectableDecorator, InjectableProvider} from './injectable'; export {Injectable, InjectableDecorator, InjectableProvider} from './injectable';
export {Injector} from './injector'; export {Injector} from './injector';
export {ProviderToken} from './provider_token';
export {ɵɵinject, inject, ɵɵinvalidFactoryDep} from './injector_compatibility'; export {ɵɵinject, inject, ɵɵinvalidFactoryDep} from './injector_compatibility';
export {INJECTOR} from './injector_token'; export {INJECTOR} from './injector_token';
export {ReflectiveInjector} from './reflective_injector'; export {ReflectiveInjector} from './reflective_injector';

View File

@ -6,13 +6,13 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {AbstractType, Type} from '../interface/type';
import {throwProviderNotFoundError} from '../render3/errors_di'; import {throwProviderNotFoundError} from '../render3/errors_di';
import {assertNotEqual} from '../util/assert'; import {assertNotEqual} from '../util/assert';
import {stringify} from '../util/stringify'; import {stringify} from '../util/stringify';
import {InjectionToken} from './injection_token';
import {getInjectableDef, ɵɵInjectableDeclaration} from './interface/defs'; import {getInjectableDef, ɵɵInjectableDeclaration} from './interface/defs';
import {InjectFlags} from './interface/injector'; import {InjectFlags} from './interface/injector';
import {ProviderToken} from './provider_token';
/** /**
@ -24,8 +24,7 @@ import {InjectFlags} from './interface/injector';
* 1. `Injector` should not depend on ivy logic. * 1. `Injector` should not depend on ivy logic.
* 2. To maintain tree shake-ability we don't want to bring in unnecessary code. * 2. To maintain tree shake-ability we don't want to bring in unnecessary code.
*/ */
let _injectImplementation: let _injectImplementation: (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)|
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|
undefined; undefined;
export function getInjectImplementation() { export function getInjectImplementation() {
return _injectImplementation; return _injectImplementation;
@ -36,10 +35,8 @@ export function getInjectImplementation() {
* Sets the current inject implementation. * Sets the current inject implementation.
*/ */
export function setInjectImplementation( export function setInjectImplementation(
impl: (<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)| impl: (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)|
undefined): undefined): (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)|undefined {
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)|
undefined {
const previous = _injectImplementation; const previous = _injectImplementation;
_injectImplementation = impl; _injectImplementation = impl;
return previous; return previous;
@ -54,8 +51,7 @@ export function setInjectImplementation(
* injectable definition. * injectable definition.
*/ */
export function injectRootLimpMode<T>( export function injectRootLimpMode<T>(
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue: T|undefined, token: ProviderToken<T>, notFoundValue: T|undefined, flags: InjectFlags): T|null {
flags: InjectFlags): T|null {
const injectableDef: ɵɵInjectableDeclaration<T>|null = getInjectableDef(token); const injectableDef: ɵɵInjectableDeclaration<T>|null = getInjectableDef(token);
if (injectableDef && injectableDef.providedIn == 'root') { if (injectableDef && injectableDef.providedIn == 'root') {
return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() : return injectableDef.value === undefined ? injectableDef.value = injectableDef.factory() :
@ -75,7 +71,7 @@ export function injectRootLimpMode<T>(
* @param fn Function which it should not equal to * @param fn Function which it should not equal to
*/ */
export function assertInjectImplementationNotEqual( export function assertInjectImplementationNotEqual(
fn: (<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T | null)) { fn: (<T>(token: ProviderToken<T>, flags?: InjectFlags) => T | null)) {
ngDevMode && ngDevMode &&
assertNotEqual(_injectImplementation, fn, 'Calling ɵɵinject would cause infinite recursion'); assertNotEqual(_injectImplementation, fn, 'Calling ɵɵinject would cause infinite recursion');
} }

View File

@ -6,10 +6,9 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {AbstractType, Type} from '../interface/type';
import {stringify} from '../util/stringify'; import {stringify} from '../util/stringify';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
import {InjectionToken} from './injection_token';
import {catchInjectorError, formatError, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, USE_VALUE, ɵɵinject} from './injector_compatibility'; import {catchInjectorError, formatError, NG_TEMP_TOKEN_PATH, setCurrentInjector, THROW_IF_NOT_FOUND, USE_VALUE, ɵɵinject} from './injector_compatibility';
import {InjectorMarkers} from './injector_marker'; import {InjectorMarkers} from './injector_marker';
import {INJECTOR} from './injector_token'; import {INJECTOR} from './injector_token';
@ -18,6 +17,7 @@ import {InjectFlags} from './interface/injector';
import {ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, ValueProvider} from './interface/provider'; import {ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, ValueProvider} from './interface/provider';
import {Inject, Optional, Self, SkipSelf} from './metadata'; import {Inject, Optional, Self, SkipSelf} from './metadata';
import {NullInjector} from './null_injector'; import {NullInjector} from './null_injector';
import {ProviderToken} from './provider_token';
import {createInjector} from './r3_injector'; import {createInjector} from './r3_injector';
import {INJECTOR_SCOPE} from './scope'; import {INJECTOR_SCOPE} from './scope';
@ -66,10 +66,9 @@ export abstract class Injector {
* @returns The instance from the injector if defined, otherwise the `notFoundValue`. * @returns The instance from the injector if defined, otherwise the `notFoundValue`.
* @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`. * @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
*/ */
abstract get<T>( abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
/** /**
* @deprecated from v4.0.0 use Type<T>, AbstractType<T> or InjectionToken<T> * @deprecated from v4.0.0 use ProviderToken<T>
* @suppress {duplicate} * @suppress {duplicate}
*/ */
abstract get(token: any, notFoundValue?: any): any; abstract get(token: any, notFoundValue?: any): any;
@ -156,8 +155,7 @@ export class StaticInjector implements Injector {
this.scope = recursivelyProcessProviders(records, providers); this.scope = recursivelyProcessProviders(records, providers);
} }
get<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
T;
get(token: any, notFoundValue?: any): any; get(token: any, notFoundValue?: any): any;
get(token: any, notFoundValue?: any, flags: InjectFlags = InjectFlags.Default): any { get(token: any, notFoundValue?: any, flags: InjectFlags = InjectFlags.Default): any {
const records = this._records; const records = this._records;

View File

@ -8,16 +8,16 @@
import '../util/ng_dev_mode'; import '../util/ng_dev_mode';
import {AbstractType, Type} from '../interface/type'; import {Type} from '../interface/type';
import {getClosureSafeProperty} from '../util/property'; import {getClosureSafeProperty} from '../util/property';
import {stringify} from '../util/stringify'; import {stringify} from '../util/stringify';
import {resolveForwardRef} from './forward_ref'; import {resolveForwardRef} from './forward_ref';
import {getInjectImplementation, injectRootLimpMode} from './inject_switch'; import {getInjectImplementation, injectRootLimpMode} from './inject_switch';
import {InjectionToken} from './injection_token';
import {Injector} from './injector'; import {Injector} from './injector';
import {DecoratorFlags, InjectFlags, InternalInjectFlags} from './interface/injector'; import {DecoratorFlags, InjectFlags, InternalInjectFlags} from './interface/injector';
import {ValueProvider} from './interface/provider'; import {ValueProvider} from './interface/provider';
import {ProviderToken} from './provider_token';
const _THROW_IF_NOT_FOUND = {}; const _THROW_IF_NOT_FOUND = {};
@ -53,11 +53,10 @@ export function setCurrentInjector(injector: Injector|null|undefined): Injector|
return former; return former;
} }
export function injectInjectorOnly<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>): T; export function injectInjectorOnly<T>(token: ProviderToken<T>): T;
export function injectInjectorOnly<T>( export function injectInjectorOnly<T>(token: ProviderToken<T>, flags?: InjectFlags): T|null;
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags): T|null; export function injectInjectorOnly<T>(token: ProviderToken<T>, flags = InjectFlags.Default): T|
export function injectInjectorOnly<T>( null {
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
if (_currentInjector === undefined) { if (_currentInjector === undefined) {
throw new Error(`inject() must be called from an injection context`); throw new Error(`inject() must be called from an injection context`);
} else if (_currentInjector === null) { } else if (_currentInjector === null) {
@ -80,11 +79,9 @@ export function injectInjectorOnly<T>(
* @codeGenApi * @codeGenApi
* @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm. * @publicApi This instruction has been emitted by ViewEngine for some time and is deployed to npm.
*/ */
export function ɵɵinject<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>): T; export function ɵɵinject<T>(token: ProviderToken<T>): T;
export function ɵɵinject<T>( export function ɵɵinject<T>(token: ProviderToken<T>, flags?: InjectFlags): T|null;
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags): T|null; export function ɵɵinject<T>(token: ProviderToken<T>, flags = InjectFlags.Default): T|null {
export function ɵɵinject<T>(
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags); return (getInjectImplementation() || injectInjectorOnly)(resolveForwardRef(token), flags);
} }
@ -138,7 +135,7 @@ Please check that 1) the type for the parameter at index ${
*/ */
export const inject = ɵɵinject; export const inject = ɵɵinject;
export function injectArgs(types: (Type<any>|InjectionToken<any>|any[])[]): any[] { export function injectArgs(types: (ProviderToken<any>|any[])[]): any[] {
const args: any[] = []; const args: any[] = [];
for (let i = 0; i < types.length; i++) { for (let i = 0; i < types.length; i++) {
const arg = resolveForwardRef(types[i]); const arg = resolveForwardRef(types[i]);

View File

@ -0,0 +1,19 @@
/**
* @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.io/license
*/
import {AbstractType, Type} from '../interface/type';
import {InjectionToken} from './injection_token';
/**
* @description
*
* Token that can be used to retrieve an instance from an injector or through a query.
*
* @publicApi
*/
export type ProviderToken<T> = Type<T>|AbstractType<T>|InjectionToken<T>;

View File

@ -9,7 +9,7 @@
import '../util/ng_dev_mode'; import '../util/ng_dev_mode';
import {OnDestroy} from '../interface/lifecycle_hooks'; import {OnDestroy} from '../interface/lifecycle_hooks';
import {AbstractType, Type} from '../interface/type'; import {Type} from '../interface/type';
import {FactoryFn, getFactoryDef} from '../render3/definition_factory'; import {FactoryFn, getFactoryDef} from '../render3/definition_factory';
import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors_di'; import {throwCyclicDependencyError, throwInvalidProviderError, throwMixedMultiProviderError} from '../render3/errors_di';
import {deepForEach, newArray} from '../util/array_utils'; import {deepForEach, newArray} from '../util/array_utils';
@ -25,6 +25,7 @@ import {getInheritedInjectableDef, getInjectableDef, getInjectorDef, InjectorTyp
import {InjectFlags} from './interface/injector'; import {InjectFlags} from './interface/injector';
import {ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, TypeProvider, ValueProvider} from './interface/provider'; import {ClassProvider, ConstructorProvider, ExistingProvider, FactoryProvider, StaticClassProvider, StaticProvider, TypeProvider, ValueProvider} from './interface/provider';
import {NullInjector} from './null_injector'; import {NullInjector} from './null_injector';
import {ProviderToken} from './provider_token';
import {INJECTOR_SCOPE} from './scope'; import {INJECTOR_SCOPE} from './scope';
@ -102,7 +103,7 @@ export class R3Injector {
* - `null` value implies that we don't have the record. Used by tree-shakable injectors * - `null` value implies that we don't have the record. Used by tree-shakable injectors
* to prevent further searches. * to prevent further searches.
*/ */
private records = new Map<Type<any>|AbstractType<any>|InjectionToken<any>, Record<any>|null>(); private records = new Map<ProviderToken<any>, Record<any>|null>();
/** /**
* The transitive set of `InjectorType`s which define this injector. * The transitive set of `InjectorType`s which define this injector.
@ -180,7 +181,7 @@ export class R3Injector {
} }
get<T>( get<T>(
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue: any = THROW_IF_NOT_FOUND, token: ProviderToken<T>, notFoundValue: any = THROW_IF_NOT_FOUND,
flags = InjectFlags.Default): T { flags = InjectFlags.Default): T {
this.assertNotDestroyed(); this.assertNotDestroyed();
// Set the injection context. // Set the injection context.
@ -404,7 +405,7 @@ export class R3Injector {
this.records.set(token, record); this.records.set(token, record);
} }
private hydrate<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, record: Record<T>): T { private hydrate<T>(token: ProviderToken<T>, record: Record<T>): T {
if (ngDevMode && record.value === CIRCULAR) { if (ngDevMode && record.value === CIRCULAR) {
throwCyclicDependencyError(stringify(token)); throwCyclicDependencyError(stringify(token));
} else if (record.value === NOT_YET) { } else if (record.value === NOT_YET) {
@ -430,8 +431,7 @@ export class R3Injector {
} }
} }
function injectableDefOrInjectorDefFactory(token: Type<any>|AbstractType<any>| function injectableDefOrInjectorDefFactory(token: ProviderToken<any>): FactoryFn<any> {
InjectionToken<any>): FactoryFn<any> {
// Most tokens will have an injectable def directly on them, which specifies a factory directly. // Most tokens will have an injectable def directly on them, which specifies a factory directly.
const injectableDef = getInjectableDef(token); const injectableDef = getInjectableDef(token);
const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token); const factory = injectableDef !== null ? injectableDef.factory : getFactoryDef(token);
@ -560,8 +560,7 @@ function hasOnDestroy(value: any): value is OnDestroy {
typeof (value as OnDestroy).ngOnDestroy === 'function'; typeof (value as OnDestroy).ngOnDestroy === 'function';
} }
function couldBeInjectableType(value: any): value is Type<any>|AbstractType<any>| function couldBeInjectableType(value: any): value is ProviderToken<any> {
InjectionToken<any> {
return (typeof value === 'function') || return (typeof value === 'function') ||
(typeof value === 'object' && value instanceof InjectionToken); (typeof value === 'object' && value instanceof InjectionToken);
} }

View File

@ -7,7 +7,7 @@
*/ */
import {InjectionToken} from '../di/injection_token'; import {InjectionToken} from '../di/injection_token';
import {Type} from '../interface/type'; import {ProviderToken} from '../di/provider_token';
import {makePropDecorator} from '../util/decorators'; import {makePropDecorator} from '../util/decorators';
/** /**
@ -169,12 +169,12 @@ export interface ContentChildrenDecorator {
* *
* @Annotation * @Annotation
*/ */
(selector: Type<any>|InjectionToken<unknown>|Function|string, opts?: { (selector: ProviderToken<unknown>|Function|string, opts?: {
descendants?: boolean, descendants?: boolean,
emitDistinctChangesOnly?: boolean, emitDistinctChangesOnly?: boolean,
read?: any, read?: any,
}): any; }): any;
new(selector: Type<any>|InjectionToken<unknown>|Function|string, new(selector: ProviderToken<unknown>|Function|string,
opts?: {descendants?: boolean, emitDistinctChangesOnly?: boolean, read?: any}): Query; opts?: {descendants?: boolean, emitDistinctChangesOnly?: boolean, read?: any}): Query;
} }
@ -240,9 +240,8 @@ export interface ContentChildDecorator {
* *
* @Annotation * @Annotation
*/ */
(selector: Type<any>|InjectionToken<unknown>|Function|string, (selector: ProviderToken<unknown>|Function|string, opts?: {read?: any, static?: boolean}): any;
opts?: {read?: any, static?: boolean}): any; new(selector: ProviderToken<unknown>|Function|string,
new(selector: Type<any>|InjectionToken<unknown>|Function|string,
opts?: {read?: any, static?: boolean}): ContentChild; opts?: {read?: any, static?: boolean}): ContentChild;
} }
@ -304,9 +303,9 @@ export interface ViewChildrenDecorator {
* *
* @Annotation * @Annotation
*/ */
(selector: Type<any>|InjectionToken<unknown>|Function|string, (selector: ProviderToken<unknown>|Function|string,
opts?: {read?: any, emitDistinctChangesOnly?: boolean}): any; opts?: {read?: any, emitDistinctChangesOnly?: boolean}): any;
new(selector: Type<any>|InjectionToken<unknown>|Function|string, new(selector: ProviderToken<unknown>|Function|string,
opts?: {read?: any, emitDistinctChangesOnly?: boolean}): ViewChildren; opts?: {read?: any, emitDistinctChangesOnly?: boolean}): ViewChildren;
} }
@ -379,9 +378,8 @@ export interface ViewChildDecorator {
* *
* @Annotation * @Annotation
*/ */
(selector: Type<any>|InjectionToken<unknown>|Function|string, (selector: ProviderToken<unknown>|Function|string, opts?: {read?: any, static?: boolean}): any;
opts?: {read?: any, static?: boolean}): any; new(selector: ProviderToken<unknown>|Function|string,
new(selector: Type<any>|InjectionToken<unknown>|Function|string,
opts?: {read?: any, static?: boolean}): ViewChild; opts?: {read?: any, static?: boolean}): ViewChild;
} }

View File

@ -10,7 +10,8 @@ import {ChangeDetectorRef as ViewEngine_ChangeDetectorRef} from '../change_detec
import {InjectionToken} from '../di/injection_token'; import {InjectionToken} from '../di/injection_token';
import {Injector} from '../di/injector'; import {Injector} from '../di/injector';
import {InjectFlags} from '../di/interface/injector'; import {InjectFlags} from '../di/interface/injector';
import {AbstractType, Type} from '../interface/type'; import {ProviderToken} from '../di/provider_token';
import {Type} from '../interface/type';
import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory'; import {ComponentFactory as viewEngine_ComponentFactory, ComponentRef as viewEngine_ComponentRef} from '../linker/component_factory';
import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver'; import {ComponentFactoryResolver as viewEngine_ComponentFactoryResolver} from '../linker/component_factory_resolver';
import {createElementRef, ElementRef as viewEngine_ElementRef} from '../linker/element_ref'; import {createElementRef, ElementRef as viewEngine_ElementRef} from '../linker/element_ref';
@ -80,9 +81,7 @@ export const SCHEDULER = new InjectionToken<((fn: () => void) => void)>('SCHEDUL
function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector { function createChainedInjector(rootViewInjector: Injector, moduleInjector: Injector): Injector {
return { return {
get: <T>( get: <T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T => {
token: Type<T>|AbstractType<T>|InjectionToken<T>, notFoundValue?: T,
flags?: InjectFlags): T => {
const value = rootViewInjector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as T, flags); const value = rootViewInjector.get(token, NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR as T, flags);
if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR || if (value !== NOT_FOUND_CHECK_ONLY_ELEMENT_INJECTOR ||

View File

@ -8,12 +8,11 @@
import {isForwardRef, resolveForwardRef} from '../di/forward_ref'; import {isForwardRef, resolveForwardRef} from '../di/forward_ref';
import {injectRootLimpMode, setInjectImplementation} from '../di/inject_switch'; import {injectRootLimpMode, setInjectImplementation} from '../di/inject_switch';
import {InjectionToken} from '../di/injection_token';
import {Injector} from '../di/injector'; import {Injector} from '../di/injector';
import {InjectorMarkers} from '../di/injector_marker'; import {InjectorMarkers} from '../di/injector_marker';
import {getInjectableDef} from '../di/interface/defs';
import {InjectFlags} from '../di/interface/injector'; import {InjectFlags} from '../di/interface/injector';
import {AbstractType, Type} from '../interface/type'; import {ProviderToken} from '../di/provider_token';
import {Type} from '../interface/type';
import {assertDefined, assertEqual, assertIndexInRange} from '../util/assert'; import {assertDefined, assertEqual, assertIndexInRange} from '../util/assert';
import {noSideEffects} from '../util/closure'; import {noSideEffects} from '../util/closure';
@ -106,7 +105,7 @@ let nextNgElementId = 0;
* @param type The directive token to register * @param type The directive token to register
*/ */
export function bloomAdd( export function bloomAdd(
injectorIndex: number, tView: TView, type: Type<any>|InjectionToken<any>|string): void { injectorIndex: number, tView: TView, type: ProviderToken<any>|string): void {
ngDevMode && assertEqual(tView.firstCreatePass, true, 'expected firstCreatePass to be true'); ngDevMode && assertEqual(tView.firstCreatePass, true, 'expected firstCreatePass to be true');
let id: number|undefined; let id: number|undefined;
if (typeof type === 'string') { if (typeof type === 'string') {
@ -264,7 +263,7 @@ export function getParentInjectorLocation(tNode: TNode, lView: LView): RelativeI
* @param token The type or the injection token to be made public * @param token The type or the injection token to be made public
*/ */
export function diPublicInInjector( export function diPublicInInjector(
injectorIndex: number, tView: TView, token: InjectionToken<any>|Type<any>): void { injectorIndex: number, tView: TView, token: ProviderToken<any>): void {
bloomAdd(injectorIndex, tView, token); bloomAdd(injectorIndex, tView, token);
} }
@ -344,8 +343,7 @@ export function injectAttributeImpl(tNode: TNode, attrNameToInject: string): str
function notFoundValueOrThrow<T>( function notFoundValueOrThrow<T>(
notFoundValue: T|null, token: Type<T>|AbstractType<T>|InjectionToken<T>, flags: InjectFlags): T| notFoundValue: T|null, token: ProviderToken<T>, flags: InjectFlags): T|null {
null {
if (flags & InjectFlags.Optional) { if (flags & InjectFlags.Optional) {
return notFoundValue; return notFoundValue;
} else { } else {
@ -363,8 +361,7 @@ function notFoundValueOrThrow<T>(
* @returns the value from the injector or throws an exception * @returns the value from the injector or throws an exception
*/ */
function lookupTokenUsingModuleInjector<T>( function lookupTokenUsingModuleInjector<T>(
lView: LView, token: Type<T>|AbstractType<T>|InjectionToken<T>, flags: InjectFlags, lView: LView, token: ProviderToken<T>, flags: InjectFlags, notFoundValue?: any): T|null {
notFoundValue?: any): T|null {
if (flags & InjectFlags.Optional && notFoundValue === undefined) { if (flags & InjectFlags.Optional && notFoundValue === undefined) {
// This must be set or the NullInjector will throw for optional deps // This must be set or the NullInjector will throw for optional deps
notFoundValue = null; notFoundValue = null;
@ -406,7 +403,7 @@ function lookupTokenUsingModuleInjector<T>(
* @returns the value from the injector, `null` when not found, or `notFoundValue` if provided * @returns the value from the injector, `null` when not found, or `notFoundValue` if provided
*/ */
export function getOrCreateInjectable<T>( export function getOrCreateInjectable<T>(
tNode: TDirectiveHostNode|null, lView: LView, token: Type<T>|AbstractType<T>|InjectionToken<T>, tNode: TDirectiveHostNode|null, lView: LView, token: ProviderToken<T>,
flags: InjectFlags = InjectFlags.Default, notFoundValue?: any): T|null { flags: InjectFlags = InjectFlags.Default, notFoundValue?: any): T|null {
if (tNode !== null) { if (tNode !== null) {
const bloomHash = bloomHashBitOrFactory(token); const bloomHash = bloomHashBitOrFactory(token);
@ -506,8 +503,8 @@ export function createNodeInjector(): Injector {
} }
function searchTokensOnInjector<T>( function searchTokensOnInjector<T>(
injectorIndex: number, lView: LView, token: Type<T>|AbstractType<T>|InjectionToken<T>, injectorIndex: number, lView: LView, token: ProviderToken<T>, previousTView: TView|null,
previousTView: TView|null, flags: InjectFlags, hostTElementNode: TNode|null) { flags: InjectFlags, hostTElementNode: TNode|null) {
const currentTView = lView[TVIEW]; const currentTView = lView[TVIEW];
const tNode = currentTView.data[injectorIndex + NodeInjectorOffset.TNODE] as TNode; const tNode = currentTView.data[injectorIndex + NodeInjectorOffset.TNODE] as TNode;
// First, we need to determine if view providers can be accessed by the starting element. // First, we need to determine if view providers can be accessed by the starting element.
@ -553,8 +550,8 @@ function searchTokensOnInjector<T>(
* @returns Index of a found directive or provider, or null when none found. * @returns Index of a found directive or provider, or null when none found.
*/ */
export function locateDirectiveOrProvider<T>( export function locateDirectiveOrProvider<T>(
tNode: TNode, tView: TView, token: Type<T>|AbstractType<T>|InjectionToken<T>|string, tNode: TNode, tView: TView, token: ProviderToken<T>|string, canAccessViewProviders: boolean,
canAccessViewProviders: boolean, isHostSpecialCase: boolean|number): number|null { isHostSpecialCase: boolean|number): number|null {
const nodeProviderIndexes = tNode.providerIndexes; const nodeProviderIndexes = tNode.providerIndexes;
const tInjectables = tView.data; const tInjectables = tView.data;
@ -568,8 +565,7 @@ export function locateDirectiveOrProvider<T>(
// When the host special case applies, only the viewProviders and the component are visible // When the host special case applies, only the viewProviders and the component are visible
const endIndex = isHostSpecialCase ? injectablesStart + cptViewProvidersCount : directiveEnd; const endIndex = isHostSpecialCase ? injectablesStart + cptViewProvidersCount : directiveEnd;
for (let i = startingIndex; i < endIndex; i++) { for (let i = startingIndex; i < endIndex; i++) {
const providerTokenOrDef = const providerTokenOrDef = tInjectables[i] as ProviderToken<any>| DirectiveDef<any>| string;
tInjectables[i] as InjectionToken<any>| Type<any>| DirectiveDef<any>| string;
if (i < directivesStart && token === providerTokenOrDef || if (i < directivesStart && token === providerTokenOrDef ||
i >= directivesStart && (providerTokenOrDef as DirectiveDef<any>).type === token) { i >= directivesStart && (providerTokenOrDef as DirectiveDef<any>).type === token) {
return i; return i;
@ -644,8 +640,7 @@ export function getNodeInjectable(
* @returns the matching bit to check in the bloom filter or `null` if the token is not known. * @returns the matching bit to check in the bloom filter or `null` if the token is not known.
* When the returned value is negative then it represents special values such as `Injector`. * When the returned value is negative then it represents special values such as `Injector`.
*/ */
export function bloomHashBitOrFactory(token: Type<any>|AbstractType<any>|InjectionToken<any>| export function bloomHashBitOrFactory(token: ProviderToken<any>|string): number|Function|undefined {
string): number|Function|undefined {
ngDevMode && assertDefined(token, 'token must be defined'); ngDevMode && assertDefined(token, 'token must be defined');
if (typeof token === 'string') { if (typeof token === 'string') {
return token.charCodeAt(0) || 0; return token.charCodeAt(0) || 0;

View File

@ -5,10 +5,10 @@
* Use of this source code is governed by an MIT-style license that can be * Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {InjectFlags, InjectionToken, resolveForwardRef} from '../../di'; import {InjectFlags, resolveForwardRef} from '../../di';
import {assertInjectImplementationNotEqual} from '../../di/inject_switch'; import {assertInjectImplementationNotEqual} from '../../di/inject_switch';
import {ɵɵinject} from '../../di/injector_compatibility'; import {ɵɵinject} from '../../di/injector_compatibility';
import {AbstractType, Type} from '../../interface/type'; import {ProviderToken} from '../../di/provider_token';
import {getOrCreateInjectable} from '../di'; import {getOrCreateInjectable} from '../di';
import {TDirectiveHostNode} from '../interfaces/node'; import {TDirectiveHostNode} from '../interfaces/node';
import {getCurrentTNode, getLView} from '../state'; import {getCurrentTNode, getLView} from '../state';
@ -37,11 +37,9 @@ import {getCurrentTNode, getLView} from '../state';
* *
* @codeGenApi * @codeGenApi
*/ */
export function ɵɵdirectiveInject<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>): T; export function ɵɵdirectiveInject<T>(token: ProviderToken<T>): T;
export function ɵɵdirectiveInject<T>( export function ɵɵdirectiveInject<T>(token: ProviderToken<T>, flags: InjectFlags): T;
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags: InjectFlags): T; export function ɵɵdirectiveInject<T>(token: ProviderToken<T>, flags = InjectFlags.Default): T|null {
export function ɵɵdirectiveInject<T>(
token: Type<T>|AbstractType<T>|InjectionToken<T>, flags = InjectFlags.Default): T|null {
const lView = getLView(); const lView = getLView();
// Fall back to inject() if view hasn't been created. This situation can happen in tests // Fall back to inject() if view hasn't been created. This situation can happen in tests
// if inject utilities are used before bootstrapping. // if inject utilities are used before bootstrapping.

View File

@ -6,9 +6,8 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {InjectionToken} from '../../di/injection_token';
import {InjectFlags} from '../../di/interface/injector'; import {InjectFlags} from '../../di/interface/injector';
import {AbstractType, Type} from '../../interface/type'; import {ProviderToken} from '../../di/provider_token';
import {assertDefined, assertEqual} from '../../util/assert'; import {assertDefined, assertEqual} from '../../util/assert';
import {TDirectiveHostNode} from './node'; import {TDirectiveHostNode} from './node';
@ -176,8 +175,7 @@ export class NodeInjectorFactory {
/** /**
* The inject implementation to be activated when using the factory. * The inject implementation to be activated when using the factory.
*/ */
injectImpl: null| injectImpl: null|(<T>(token: ProviderToken<T>, flags?: InjectFlags) => T);
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T);
/** /**
* Marker set to true during factory invocation to see if we get into recursive loop. * Marker set to true during factory invocation to see if we get into recursive loop.
@ -280,8 +278,7 @@ export class NodeInjectorFactory {
* Set to `true` if the token is declared in `viewProviders` (or if it is component). * Set to `true` if the token is declared in `viewProviders` (or if it is component).
*/ */
isViewProvider: boolean, isViewProvider: boolean,
injectImplementation: null| injectImplementation: null|(<T>(token: ProviderToken<T>, flags?: InjectFlags) => T)) {
(<T>(token: Type<T>|AbstractType<T>|InjectionToken<T>, flags?: InjectFlags) => T)) {
ngDevMode && assertDefined(factory, 'Factory not specified'); ngDevMode && assertDefined(factory, 'Factory not specified');
ngDevMode && assertEqual(typeof factory, 'function', 'Expected factory function.'); ngDevMode && assertEqual(typeof factory, 'function', 'Expected factory function.');
this.canSeeViewProviders = isViewProvider; this.canSeeViewProviders = isViewProvider;

View File

@ -6,8 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {InjectionToken} from '../../di/injection_token'; import {ProviderToken} from '../../di/provider_token';
import {Type} from '../../interface/type';
import {QueryList} from '../../linker/query_list'; import {QueryList} from '../../linker/query_list';
import {TNode} from './node'; import {TNode} from './node';
@ -17,7 +16,7 @@ import {TView} from './view';
* An object representing query metadata extracted from query annotations. * An object representing query metadata extracted from query annotations.
*/ */
export interface TQueryMetadata { export interface TQueryMetadata {
predicate: Type<any>|InjectionToken<unknown>|string[]; predicate: ProviderToken<unknown>|string[];
read: any; read: any;
flags: QueryFlags; flags: QueryFlags;
} }

View File

@ -6,8 +6,8 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {InjectionToken} from '../../di/injection_token';
import {Injector} from '../../di/injector'; import {Injector} from '../../di/injector';
import {ProviderToken} from '../../di/provider_token';
import {Type} from '../../interface/type'; import {Type} from '../../interface/type';
import {SchemaMetadata} from '../../metadata/schema'; import {SchemaMetadata} from '../../metadata/schema';
import {Sanitizer} from '../../sanitization/sanitizer'; import {Sanitizer} from '../../sanitization/sanitizer';
@ -904,9 +904,8 @@ export type DestroyHookData = (HookEntry|HookData)[];
* *
* Injector bloom filters are also stored here. * Injector bloom filters are also stored here.
*/ */
export type TData = export type TData = (TNode|PipeDef<any>|DirectiveDef<any>|ComponentDef<any>|number|TStylingRange|
(TNode|PipeDef<any>|DirectiveDef<any>|ComponentDef<any>|number|TStylingRange|TStylingKey| TStylingKey|ProviderToken<any>|TI18n|I18nUpdateOpCodes|TIcu|null|string)[];
Type<any>|InjectionToken<any>|TI18n|I18nUpdateOpCodes|TIcu|null|string)[];
// Note: This hack is necessary so we don't erroneously get a circular dependency // Note: This hack is necessary so we don't erroneously get a circular dependency
// failure based on types. // failure based on types.

View File

@ -9,8 +9,7 @@
// We are temporarily importing the existing viewEngine_from core so we can be sure we are // We are temporarily importing the existing viewEngine_from core so we can be sure we are
// correctly implementing its interfaces for backwards compatibility. // correctly implementing its interfaces for backwards compatibility.
import {InjectionToken} from '../di/injection_token'; import {ProviderToken} from '../di/provider_token';
import {Type} from '../interface/type';
import {createElementRef, ElementRef as ViewEngine_ElementRef, unwrapElementRef} from '../linker/element_ref'; import {createElementRef, ElementRef as ViewEngine_ElementRef, unwrapElementRef} from '../linker/element_ref';
import {QueryList} from '../linker/query_list'; import {QueryList} from '../linker/query_list';
import {createTemplateRef, TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref'; import {createTemplateRef, TemplateRef as ViewEngine_TemplateRef} from '../linker/template_ref';
@ -88,7 +87,7 @@ class LQueries_ implements LQueries {
class TQueryMetadata_ implements TQueryMetadata { class TQueryMetadata_ implements TQueryMetadata {
constructor( constructor(
public predicate: Type<any>|InjectionToken<unknown>|string[], public flags: QueryFlags, public predicate: ProviderToken<unknown>|string[], public flags: QueryFlags,
public read: any = null) {} public read: any = null) {}
} }
@ -456,7 +455,7 @@ export function ɵɵqueryRefresh(queryList: QueryList<any>): boolean {
* @codeGenApi * @codeGenApi
*/ */
export function ɵɵviewQuery<T>( export function ɵɵviewQuery<T>(
predicate: Type<any>|InjectionToken<unknown>|string[], flags: QueryFlags, read?: any): void { predicate: ProviderToken<unknown>|string[], flags: QueryFlags, read?: any): void {
ngDevMode && assertNumber(flags, 'Expecting flags'); ngDevMode && assertNumber(flags, 'Expecting flags');
const tView = getTView(); const tView = getTView();
if (tView.firstCreatePass) { if (tView.firstCreatePass) {
@ -481,8 +480,8 @@ export function ɵɵviewQuery<T>(
* @codeGenApi * @codeGenApi
*/ */
export function ɵɵcontentQuery<T>( export function ɵɵcontentQuery<T>(
directiveIndex: number, predicate: Type<any>|InjectionToken<unknown>|string[], directiveIndex: number, predicate: ProviderToken<unknown>|string[], flags: QueryFlags,
flags: QueryFlags, read?: any): void { read?: any): void {
ngDevMode && assertNumber(flags, 'Expecting flags'); ngDevMode && assertNumber(flags, 'Expecting flags');
const tView = getTView(); const tView = getTView();
if (tView.firstCreatePass) { if (tView.firstCreatePass) {

View File

@ -12,7 +12,6 @@
/* clang-format off */ /* clang-format off */
import { import {
AbstractType,
Component, Component,
Directive, Directive,
InjectFlags, InjectFlags,
@ -22,6 +21,7 @@ import {
NgZone, NgZone,
Pipe, Pipe,
PlatformRef, PlatformRef,
ProviderToken,
Type, Type,
ɵflushModuleScopingQueueAsMuchAsPossible as flushModuleScopingQueueAsMuchAsPossible, ɵflushModuleScopingQueueAsMuchAsPossible as flushModuleScopingQueueAsMuchAsPossible,
ɵRender3ComponentFactory as ComponentFactory, ɵRender3ComponentFactory as ComponentFactory,
@ -156,19 +156,14 @@ export class TestBedRender3 implements TestBed {
return TestBedRender3 as any as TestBedStatic; return TestBedRender3 as any as TestBedStatic;
} }
static inject<T>( static inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; static inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
static inject<T>( static inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|null;
static inject<T>(
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
flags?: InjectFlags): T|null {
return _getTestBedRender3().inject(token, notFoundValue, flags); return _getTestBedRender3().inject(token, notFoundValue, flags);
} }
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
static get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; static get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
static get(token: any, notFoundValue?: any): any; static get(token: any, notFoundValue?: any): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
@ -263,14 +258,9 @@ export class TestBedRender3 implements TestBed {
return this.compiler.compileComponents(); return this.compiler.compileComponents();
} }
inject<T>( inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
inject<T>( inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|null;
inject<T>(
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
flags?: InjectFlags): T|null {
if (token as unknown === TestBedRender3) { if (token as unknown === TestBedRender3) {
return this as any; return this as any;
} }
@ -281,7 +271,7 @@ export class TestBedRender3 implements TestBed {
} }
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get(token: any, notFoundValue?: any): any; get(token: any, notFoundValue?: any): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {AbstractType, ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDeclaration} from '@angular/core'; import {ApplicationInitStatus, CompilerOptions, Component, Directive, InjectFlags, InjectionToken, Injector, NgModule, NgModuleFactory, NgModuleRef, NgZone, Optional, Pipe, PlatformRef, Provider, ProviderToken, SchemaMetadata, SkipSelf, StaticProvider, Type, ɵclearOverrides as clearOverrides, ɵDepFlags as DepFlags, ɵgetInjectableDef as getInjectableDef, ɵINJECTOR_SCOPE as INJECTOR_SCOPE, ɵivyEnabled as ivyEnabled, ɵNodeFlags as NodeFlags, ɵoverrideComponentView as overrideComponentView, ɵoverrideProvider as overrideProvider, ɵstringify as stringify, ɵɵInjectableDeclaration} from '@angular/core';
import {AsyncTestCompleter} from './async_test_completer'; import {AsyncTestCompleter} from './async_test_completer';
import {ComponentFixture} from './component_fixture'; import {ComponentFixture} from './component_fixture';
@ -53,14 +53,11 @@ export interface TestBed {
compileComponents(): Promise<any>; compileComponents(): Promise<any>;
inject<T>( inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
inject<T>(
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|null;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get(token: any, notFoundValue?: any): any; get(token: any, notFoundValue?: any): any;
@ -216,19 +213,14 @@ export class TestBedViewEngine implements TestBed {
return TestBedViewEngine as any as TestBedStatic; return TestBedViewEngine as any as TestBedStatic;
} }
static inject<T>( static inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; static inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
static inject<T>( static inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|null;
static inject<T>(
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
flags?: InjectFlags): T|null {
return _getTestBedViewEngine().inject(token, notFoundValue, flags); return _getTestBedViewEngine().inject(token, notFoundValue, flags);
} }
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
static get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; static get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** /**
* @deprecated from v9.0.0 use TestBed.inject * @deprecated from v9.0.0 use TestBed.inject
* @suppress {duplicate} * @suppress {duplicate}
@ -469,14 +461,9 @@ export class TestBedViewEngine implements TestBed {
} }
} }
inject<T>( inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
inject<T>( inject<T>(token: ProviderToken<T>, notFoundValue?: T|null, flags?: InjectFlags): T|null {
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|null;
inject<T>(
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T|null,
flags?: InjectFlags): T|null {
this._initIfNeeded(); this._initIfNeeded();
if (token as unknown === TestBed) { if (token as unknown === TestBed) {
return this as any; return this as any;
@ -490,7 +477,7 @@ export class TestBedViewEngine implements TestBed {
} }
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get(token: any, notFoundValue?: any): any; get(token: any, notFoundValue?: any): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */

View File

@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {AbstractType, Component, Directive, InjectFlags, InjectionToken, NgModule, Pipe, PlatformRef, SchemaMetadata, Type} from '@angular/core'; import {Component, Directive, InjectFlags, InjectionToken, NgModule, Pipe, PlatformRef, ProviderToken, SchemaMetadata, Type} from '@angular/core';
import {ComponentFixture} from './component_fixture'; import {ComponentFixture} from './component_fixture';
import {MetadataOverride} from './metadata_override'; import {MetadataOverride} from './metadata_override';
@ -114,14 +114,11 @@ export interface TestBedStatic {
deps?: any[], deps?: any[],
}): TestBedStatic; }): TestBedStatic;
inject<T>( inject<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T; inject<T>(token: ProviderToken<T>, notFoundValue: null, flags?: InjectFlags): T|null;
inject<T>(
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue: null, flags?: InjectFlags): T
|null;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get<T>(token: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): any; get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): any;
/** @deprecated from v9.0.0 use TestBed.inject */ /** @deprecated from v9.0.0 use TestBed.inject */
get(token: any, notFoundValue?: any): any; get(token: any, notFoundValue?: any): any;

View File

@ -6,14 +6,12 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
import {AbstractType, inject, InjectFlags, InjectionToken, Injector, Type, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core'; import {inject, InjectFlags, InjectionToken, Injector, ProviderToken, ɵsetCurrentInjector as setCurrentInjector} from '@angular/core';
class MockRootScopeInjector implements Injector { class MockRootScopeInjector implements Injector {
constructor(readonly parent: Injector) {} constructor(readonly parent: Injector) {}
get<T>( get<T>(token: ProviderToken<T>, defaultValue?: any, flags: InjectFlags = InjectFlags.Default): T {
token: Type<T>|AbstractType<T>|InjectionToken<T>, defaultValue?: any,
flags: InjectFlags = InjectFlags.Default): T {
if ((token as any).ɵprov && (token as any).ɵprov.providedIn === 'root') { if ((token as any).ɵprov && (token as any).ɵprov.providedIn === 'root') {
const old = setCurrentInjector(this); const old = setCurrentInjector(this);
try { try {