microsoft / microsoft/TypeScript
The intersection of a tuple with an unrelated array is handled inconsistently
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.4k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 117
Description
Bug Report
🔎 Search Terms
tuple, intersection, array, unrelated, narrowing, index signature
🕗 Version & Regression Information
This is the behavior in every version I tried
⏯ Playground Link
Playground link with relevant code
💻 Code
/* unrelated array */
type ShouldBeNever = string[] & [1, 2, 3]
type OK = (ShouldBeNever)[number] // never
type NotOK = (ShouldBeNever)[1] // 2
type WeirdOverload = (ShouldBeNever)['pop'] // {
// (): string | undefined
// (): 3 | 1 | 2 | undefined
//}
const isString = ([1, 2, 3] as ShouldBeNever).pop() // string | undefined
/* related array but not a supertype */
type ShouldBeNarrowed = [number | string, number | boolean] & (string | boolean | symbol)[]
type FF = ShouldBeNarrowed[number] // string | boolean
type HH = ShouldBeNarrowed[0] // string | number
🙁 Actual behavior
The index signature is appropriately updated, but not the individual elements nor the methods operating on the resulting tuple. Additionally, methods get overloaded, so when calling pop for example, the first overload is selected and the return type is not the intersection of the original components return types as it should be.
🙂 Expected behavior
I would expect ShouldBeNever to be [never, never, never] and ShouldBeNarrowed to be [string, boolean]
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 indexed access and array-method results for ShouldBeNever and ShouldBeNarrowed. Trace how tuple intersections update index signatures, element types, and methods; done means the examples produce the expected never and narrowed tuple types without inconsistent overload results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100