Skip to content

regression in 3.1+: mapped type cannot be used to index type #27413

Closed
@yseymour

Description

@yseymour

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions