-
Notifications
You must be signed in to change notification settings - Fork 12.8k
T[keyof T] assignable to T[K] #17166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks like TS is interpreting Another instance of this: interface Foo {
s: string;
n: number;
}
function g<K extends keyof Foo>() {
var indexed: Foo[K] = 'what'; // no error? what if K is 'n'?
} I doubt this is intended. It seems like a design limitation, if not a bug. |
@jcalz I am also in doubt about this, because there is no specification for this case all I can is to pretend it to be a bug) |
@olegdunkan the fix for your bug is up at #17912. @jcalz your repro exposes a design limitation; if we distinguished the types of read locations and write locations then we could say that the type of However, read/write distinction is similar to variance handling, so we are unlikely to add one set of features without the other. And that set of features is very complex, both to use and to implement, so I don't think it will happen soon, if at all. |
TypeScript Version: 2.4.0 / nightly (2.5.0-dev.201xxxxx)
Code
Expected behavior:
Compiler error
Actual behavior:
Runtime error
The text was updated successfully, but these errors were encountered: