TypeScript Version: 2.1.4
Code
// Type with index signature
type StringToNumber = {[id: string]: number};
// This works!
type ShouldBeNumber = StringToNumber[keyof StringToNumber];
let x: ShouldBeNumber = <number>0;
let y: number = x;
// This doesn't work.
class Pred<X extends StringToNumber> {
test(value: X[keyof X]) {
// error TS2322: type 'X[keyof X]' is not assignable to type 'number'
let slot: number = value;
// error TS2352: Type 'X[keyof X]' cannot be converted to type 'number'.
let slot2 = <number> value;
}
}
Expected behavior:
If I understand the spec correctly, all of X's properties must be subtypes of their corresponding properties in StringToNumber. All of StringToNumber's properties are of type number, so X[keyof X] should be a subtype of / assignable to number.
Actual behavior:
As far as I can tell, no relationship is inferred between the types X[keyof X] and number.
TypeScript Version: 2.1.4
Code
Expected behavior:
If I understand the spec correctly, all of
X's properties must be subtypes of their corresponding properties inStringToNumber. All ofStringToNumber's properties are of typenumber, soX[keyof X]should be a subtype of / assignable tonumber.Actual behavior:
As far as I can tell, no relationship is inferred between the types
X[keyof X]andnumber.