microsoft / microsoft/TypeScript

Nested indexing of mapped type fails to resolve correctly

Open
#28,269 1 comment 1 reaction 1 assignee View on GitHub

@weswigham is already working on this.

Since Dec 8, 2018.

Bug Domain: Indexed Access Types
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

TypeScript Version: 3.2.0-dev.20181031

Search Terms:

nested indexing mapped type

Code

interface Foo {
  a: { x: boolean };
  b: { y: boolean };
}

function extractBoolean<K extends 'a' | 'b'>(foo: Foo, key: K, innerKey: keyof Foo[K]): boolean {
  return foo[key][innerKey];
}

Expected behavior:

Should compile.

Actual behavior:

Type 'Foo[K][keyof Foo[K]]' is not assignable to type 'boolean'.
  Type '({ x: boolean; } | { y: boolean; })[keyof Foo[K]]' is not assignable to type 'boolean'.

Playground Link

Related Issues:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.