-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
Search Terms:
T[keyof T]
Code
class Unbounded<T> {
foo(x: T[keyof T]) {
let y: {}|undefined|null = x;
}
}
Expected behavior:
Not absolutely sure, but I would like to be able to reason about T[keyof T]
in terms of the types I already known - either it should behave like {} | null | undefined
or like never
. Or maybe I shouldn't be allowed to write that type.
Actual behavior:
Type 'T[keyof T]' is not assignable to type '{} | null | undefined'.
We noticed this during upgrading TS2.6 to TS2.7. It appears in TS2.6 this assignment was allowed for if one wrote Bounded<T extends {}>
, where as in 2.7 and 2.8 that makes no difference. As expected when then lower bound has actual keys, they are used.
P.S. I miss the TS spec.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue