Closed
Description
TypeScript Version: 3.1.1 and 3.2.0-dev.20180927
Search Terms:
mapped type index
Code
// Given:
// T = {foo: number}
// The return type of T.select({bar: 'foo'}) should be
// {bar: number}
interface Table<T> {
select<U extends {[K: string]: keyof T}>
(fields: U): {[K in keyof U]: T[U[K]]}
}
Expected behavior:
U[K] is keyof T and so T[U[K]] is computed successfully
Actual behavior:
Gives the error "Type 'U[K]' cannot be used to index type 'T'".
The same code compiles with tsc 3.0.3 and the return type gets computed correctly.