Skip to content

Commit

Permalink
fixup! feat(core): support object-based DI flags in TestBed.inject()
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewKushnir committed Sep 23, 2022
1 parent ad411b8 commit 8690b13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions goldens/public-api/core/index.md
Expand Up @@ -492,6 +492,9 @@ export const ENVIRONMENT_INITIALIZER: InjectionToken<() => void>;
export abstract class EnvironmentInjector implements Injector {
// (undocumented)
abstract destroy(): void;
abstract get<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & {
optional: true;
}): T | null;
abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, options?: InjectOptions): T;
// @deprecated
abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
Expand Down Expand Up @@ -733,6 +736,9 @@ export abstract class Injector {
parent?: Injector;
name?: string;
}): Injector;
abstract get<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions & {
optional: true;
}): T | null;
abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, options?: InjectOptions | InjectFlags): T;
// @deprecated
abstract get<T>(token: ProviderToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
Expand Down
9 changes: 9 additions & 0 deletions packages/core/src/di/injector.ts
Expand Up @@ -51,6 +51,15 @@ export abstract class Injector {
* It can **not** be done in minor/patch, since it's breaking for custom injectors
* that only implement the old `InjectorFlags` interface.
*/

/**
* Retrieves an instance from the injector based on the provided token.
* @returns The instance from the injector if defined, otherwise the `notFoundValue`.
* @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
*/
abstract get<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions&{
optional: true;
}): T|null;
/**
* Retrieves an instance from the injector based on the provided token.
* @returns The instance from the injector if defined, otherwise the `notFoundValue`.
Expand Down
8 changes: 8 additions & 0 deletions packages/core/src/di/r3_injector.ts
Expand Up @@ -77,6 +77,14 @@ interface Record<T> {
* @developerPreview
*/
export abstract class EnvironmentInjector implements Injector {
/**
* Retrieves an instance from the injector based on the provided token.
* @returns The instance from the injector if defined, otherwise the `notFoundValue`.
* @throws When the `notFoundValue` is `undefined` or `Injector.THROW_IF_NOT_FOUND`.
*/
abstract get<T>(token: ProviderToken<T>, notFoundValue: undefined, options: InjectOptions&{
optional: true;
}): T|null;
/**
* Retrieves an instance from the injector based on the provided token.
* @returns The instance from the injector if defined, otherwise the `notFoundValue`.
Expand Down

0 comments on commit 8690b13

Please sign in to comment.