microsoft / microsoft/TypeScript
Nested indexing of mapped type fails to resolve correctly
Open
@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'.
Related Issues:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.