Tuple with element after spread not assignable to tuple with rest elements #33573
Copy link
Copy link
Closed
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
Activity
This is my current workaround,
const src : readonly [number, ...number[]] = [1,2,3,4,5] as const; interface ReadonlyArray<T> { concat ( this : readonly [T, ...T[]], ...items: (T | ConcatArray<T>)[] ) : ([T, ...T[]]) } //Expected: OK //Actual : OK const dst2 : [number, ...number[]] = src.concat(1337); console.log(src); console.log(dst2);
If anyone is using this for a tuple-of-arrays, you'll need,
const src : readonly [[number, number], ...[number, number][]] = [[1,2], [3,4]]; interface ReadonlyArray<T> { concat ( this : readonly [T, ...T[]], ...items: (T | ConcatArray<T>)[] ) : ([T, ...T[]]) } interface Array<T> { concat ( this : readonly [T, ...T[]], ...items: (T | ConcatArray<T>)[] ) : ([T, ...T[]]) } //Expected: OK //Actual : OK const dst2 : readonly [[number, number], ...[number, number][]] = src.concat([5,6]); console.log(src); console.log(dst2);
Should the above overloads for
concatbe added to thelib.d.tsfiles?Andarist commented
on Feb 18, 2023 ContributorMore actionsRyan Cavanaugh (@RyanCavanaugh) this works OK today, the issue can be closed
Just looking at old issues; this was fixed in #39094.
- locked as resolved and limited conversation to collaborators
on Oct 21, 2025
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript
TypeScript Version: 3.5.1, 3.6.3, Nightly (2019-09-24)
Search Terms:
Tuple, spread, assignability
Code
Expected behavior:
Assignment to
dst1should succeed.It should succeed because
headisnumberand...tail, 1337should correspond to...number[]Actual behavior:
Assignment to
dst1fails.Playground Link:
3.5.1 Playground
Related Issues:
Possibly this,
#29248
It mentions spread arguments, and an extra argument at the end causes TS to not realize there are the right number of arguments.
However, this repro just has tuples not being assignable to other tuples.