microsoft / microsoft/TypeScript
extends causing string literal can't be used as index
Open
Nobody has claimed this yet.
Domain: Indexed Access Types
Possible Improvement
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
cannot be used as an index type
🕗 Version & Regression Information
- This changed between versions 4.9.5 and 5.0.4
⏯ Playground Link
Playground link with relevant code
💻 Code
interface Dict {
foo: 1
bar: 1
}
type A = Dict['foo'] // works
type F = 'foo'
type B = Dict[F] // works
type FF = 'foo' extends ('foo' | 'bar') ? 'foo' : never // in theory, FF === F
type C = Dict[FF] // not working, Type '"foo"' cannot be used as an index type.(2538)
🙁 Actual behavior
type C throws error
🙂 Expected behavior
no error
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 linked TypeScript Playground and reproduce the minimal Dict, F, FF, and C example across the reported versions. Trace the indexed-access type-checking path for a conditional type that resolves to a string literal, then add a regression test based on this example. Done means type C = Dict[FF] produces no error.
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
- 45/100