microsoft / microsoft/TypeScript
`never` as keyof tuples/arrays behaves the same as `number`
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
🔎 Search Terms
tuple keyof never, tuple[never], array keyof never
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about this issue
Versions I tried:
- 5.2.2
- nightly (playground)
⏯ Playground Link
💻 Code
type A = {}[never] // ✅ never
type B = { a: string }[never] // ✅ never
type C = [][never] // ✅ never
type D = [string][never] // ❌ string
type E = string[][never] // ❌ string
type F = (string | number)[][never] // ❌ string | number
🙁 Actual behavior
After using a never key on tuples/arrays you get back the entirety of the tuple/array elements type.
🙂 Expected behavior
After using a never key on tuples/arrays you get back never, as when dealing with objects.
Additional information about the issue
Not sure if this has historical reasons to behave like it does, but couldn't find any specific info about it.
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 by reproducing the behavior in the linked TypeScript Playground, comparing the object, tuple, and array examples using never. Trace the compiler's indexed-access handling for tuple and array keys; done means those examples evaluate to never consistently with object indexing, with appropriate regression coverage.
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
- 35/100