refactor(core): remove deprecated OpaqueToken
(#18971)
BREAKING CHANGE: `OpaqueToken` has been removed as it was deprecated since v4. Use `InjectionToken` instead. PR Close #18971
This commit is contained in:

committed by
Miško Hevery

parent
36d37cc6ae
commit
3c4eef8a86
@ -21,4 +21,4 @@ export {ReflectiveInjector} from './di/reflective_injector';
|
||||
export {StaticProvider, ValueProvider, ExistingProvider, FactoryProvider, Provider, TypeProvider, ClassProvider} from './di/provider';
|
||||
export {ResolvedReflectiveFactory, ResolvedReflectiveProvider} from './di/reflective_provider';
|
||||
export {ReflectiveKey} from './di/reflective_key';
|
||||
export {InjectionToken, OpaqueToken} from './di/injection_token';
|
||||
export {InjectionToken} from './di/injection_token';
|
||||
|
@ -6,35 +6,6 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* Creates a token that can be used in a DI Provider.
|
||||
*
|
||||
* ### Example ([live demo](http://plnkr.co/edit/Ys9ezXpj2Mnoy3Uc8KBp?p=preview))
|
||||
*
|
||||
* ```typescript
|
||||
* var t = new OpaqueToken("value");
|
||||
*
|
||||
* var injector = Injector.resolveAndCreate([
|
||||
* {provide: t, useValue: "bindingValue"}
|
||||
* ]);
|
||||
*
|
||||
* expect(injector.get(t)).toEqual("bindingValue");
|
||||
* ```
|
||||
*
|
||||
* Using an `OpaqueToken` is preferable to using strings as tokens because of possible collisions
|
||||
* caused by multiple providers using the same string as two different tokens.
|
||||
*
|
||||
* Using an `OpaqueToken` is preferable to using an `Object` as tokens because it provides better
|
||||
* error messages.
|
||||
* @deprecated since v4.0.0 because it does not support type information, use `InjectionToken<?>`
|
||||
* instead.
|
||||
*/
|
||||
export class OpaqueToken {
|
||||
constructor(protected _desc: string) {}
|
||||
|
||||
toString(): string { return `Token ${this._desc}`; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a token that can be used in a DI Provider.
|
||||
*
|
||||
@ -57,11 +28,8 @@ export class OpaqueToken {
|
||||
*
|
||||
* @stable
|
||||
*/
|
||||
export class InjectionToken<T> extends OpaqueToken {
|
||||
// This unused property is needed here so that TS can differentiate InjectionToken from
|
||||
// OpaqueToken since otherwise they would have the same shape and be treated as equivalent.
|
||||
private _differentiate_from_OpaqueToken_structurally: any;
|
||||
constructor(desc: string) { super(desc); }
|
||||
export class InjectionToken<T> {
|
||||
constructor(protected _desc: string) {}
|
||||
|
||||
toString(): string { return `InjectionToken ${this._desc}`; }
|
||||
|
||||
|
Reference in New Issue
Block a user