Closed
Description
TypeScript Version:
2.7.1
2.8.0-dev.20180208
Search Terms:
inferred generic index
Code
type Dict<T extends string> = { [key in T]: number }
type DictDict<V extends string, T extends string> = { [key in V]: Dict<T> }
function f<V extends string, T extends string>(dd: DictDict<V, T>, k1: V, k2: T): number {
// Type 'DictDict<V, T>[V][T]' is not assignable to type 'number'.
return dd[k1][k2]
}
// works
function f1<V extends string, T extends string>(dd: DictDict<V, T>, k1: V, k2: T): number {
const d: Dict<T> = dd[k1]
return d[k2]
}
Expected behavior:
The code above works on typescript 2.6.2, where dd[k1][k2] in f appears to correctly infer number as the type.
Actual behavior:
In >= 2.7.1, typescript now appears to need help figuring out the type of dd[k1].
Playground Link:
Related Issues:
21368