Closed
Labels
BugA bug in TypeScriptA bug in TypeScript
Milestone
Description
TypeScript Version: 3.5.1, 3.6.3, Nightly (2019-09-24)
Search Terms:
Tuple, spread, assignability
Code
declare const src : [number, ...number[]];
const [head, ...tail] = src;
//Expected: OK
//Actual : OK
const dst0 : [number, ...number[]] = [head, ...tail];
//Expected: OK
//Actual : Error
//Property '0' is missing in type 'number[]' but required in type '[number, ...number[]]'.
const dst1 : [number, ...number[]] = [head, ...tail, 1337];Expected behavior:
Assignment to dst1 should succeed.
It should succeed because head is number and ...tail, 1337 should correspond to ...number[]
Actual behavior:
Assignment to dst1 fails.
Playground Link:
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.
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScript
Activity
AnyhowStep commentedon Sep 24, 2019
This is my current workaround,
3.5.1 Playground
If anyone is using this for a tuple-of-arrays, you'll need,
3.5.1 Playground
Should the above overloads for
concatbe added to thelib.d.tsfiles?Andarist commentedon Feb 18, 2023
Ryan Cavanaugh (@RyanCavanaugh) this works OK today, the issue can be closed
jakebailey commentedon Jul 9, 2023
Just looking at old issues; this was fixed in #39094.