Skip to content

Tuple with element after spread not assignable to tuple with rest elements #33573

Closed
@AnyhowStep

Description

@AnyhowStep

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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions