InjectionToken
was introduced in Angular 4 and OpaqueToken
was marked as deprecated.
According to the manual, it is supposed to be used as
const anyToken = new InjectionToken('any');
for untyped token, and as
const numberToken = new InjectionToken<number>('number');
for typed token.
However, typed token still can be injected and used with different type when it is injected, TypeScript will be ok with this, won't it?
constructor(@Inject(numberToken) any, @Inject(numberToken) string: string) { ... }
How is InjectionToken
supposed to benefit from TypeScript type system?
Why was OpaqueToken
deprecated if there's no practical difference between those two?