-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Closed
Copy link
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
Angular's dependency injection looks something like this:
interface Type<T> extends Function {
new (...args: any[]): T;
}
function get<T>(token: Type<T>, notFoundValue?: T): T {
return null as any as T;
}
class Token0 {
a = 1;
}
class Token1 {
static a = 1;
}
let t0 = get(Token0); // t0 always inferred as Token0
let t1 = get(Token1); // TS 2.5.3: t1 inferred as `{}`
// TS 2.6.1 t1 inferred as `Token1`
As stated in those comments, starting in TS 2.5 we get the wrong type when a user asks the Injector
for a Token with a static member. It's later fixed in TS 2.6.
Workaround is to give an explicit type argument to get
, eg Angular users should repeat the type like Injector.get<Token1>(Token1)
There may be no action required here other than asking users to upgrade to TS 2.6 - but sadly Angular doesn't support it yet because we need to upgrade all the places we depend on first. Filing this issue mostly so we have a place to point to in the Angular changelog.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript