feat(core): Introduce TestBed.inject to replace TestBed.get (#32200)
TestBed.get is not type safe, fixing it would be a massive breaking change. The Angular team has proposed replacing it with TestBed.inject and deprecate TestBed.get. Deprecation from TestBed.get will come as a separate commit. Issue #26491 Fixes #29905 BREAKING CHANGE: Injector.get now accepts abstract classes to return type-safe values. Previous implementation returned `any` through the deprecated implementation. PR Close #32200
This commit is contained in:

committed by
Misko Hevery

parent
2b28b91fd9
commit
3aba7ebe6a
@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {Type} from '../interface/type';
|
||||
import {AbstractType, Type} from '../interface/type';
|
||||
import {stringify} from '../util/stringify';
|
||||
|
||||
import {resolveForwardRef} from './forward_ref';
|
||||
@ -55,7 +55,8 @@ export abstract class Injector {
|
||||
* @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: Type<T>|InjectionToken<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
abstract get<T>(
|
||||
token: Type<T>|InjectionToken<T>|AbstractType<T>, notFoundValue?: T, flags?: InjectFlags): T;
|
||||
/**
|
||||
* @deprecated from v4.0.0 use Type<T> or InjectionToken<T>
|
||||
* @suppress {duplicate}
|
||||
|
Reference in New Issue
Block a user