Closed
Description
TypeScript Version: 2.2.0
Code
function foo<T>() {
let x: { [P in keyof T]: number }
let y: { [k: string]: number } = x;
}
Expected behavior:
The assigment should be allowed.
Actual behavior:
The assignment isn't allowed.
This is despite this variant working just fine:
let x: {[P in 'one' | 'two']: number } = null;
let y: { [k: string]: number } = x;
And this works too, as just as the documentation states, keyof T
is a subtype of string
for all T
:
function foo<T>() {
let kt: keyof T = '' as keyof T;
let sn: string = kt;
}