microsoft / microsoft/TypeScript
Error: Type cannot be used to index type after two indexes
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: 2.7.1, 2.8.0-dev.20180208
Search Terms:
Type cannot be used to index type
Code
interface IExample {
foo: {
bar: {
baz: number;
}
}
}
type F = <
name extends keyof IExample,
val extends keyof IExample[name]
>() => IExample[name][val]['baz']; // ← Type '"baz"' cannot be used to index type 'IExample[name][val]'.
Expected behavior:
In version 2.7.0-dev.20171115 this code was checking without errors.
Actual behavior:
Now in throws error: Type '"baz"' cannot be used to index type 'IExample[name][val]'.
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.
Research direction
Start with the TypeScript Playground reproduction in the issue and compare its behavior across the reported compiler versions, focusing on the generic indexed-access expression IExample[name][val]['baz']. Trace the type-checking path for the second indexed access and verify that the example checks without errors when the fix is complete.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100