Microsoft/TypeScript
GitHub ã§èŠãTuple Spread Inconsistencies When Intersected
Open
#60,539 opened on 2024幎11æ19æ¥
BugDomain: IntersectionHelp Wanted
Repository metrics
- Stars
- Â (48,455 stars)
- PR merge metrics
-  (å¹³åããŒãž 6d 17h) (30d ã§ 9 merged PRs)
説æ
ð Search Terms
Tuple, Intersection, Spread
ð Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about tuples and arrays
⯠Playground Link
ð» Code
type Tuple = [string, ...number[]];
type TupleIntersection = Tuple & { prop: string };
type TupleRestAccess = Tuple[1];
// ^ number
type TupleIntersectionRestAccess = TupleIntersection[1];
// ^ string | number
type TupleSpread = [...Tuple];
// ^ [string, ...number[]]
type TupleIntersectionSpread = [...TupleIntersection];
// ^ (string | number)[]
ð Actual behavior
TupleIntersection[1] and [...TupleIntersection] both seem to use an overly broad type, matching the number index signature instead of the more narrow spread signature.
What I mean is that TupleIntersection[1] behaves just like Tuple[number] does. This leads me to believe that the number index signature is synthesized correctly but the logic for numeric literals in the range of the spread signature aren't handled.
ð Expected behavior
I expected Tuple's behaviour to match TupleIntersection.
Additional information about the issue
No response