Skip to content

Tuples should be clonable with Array.prototype.slice() #4988

Closed
@vjau

Description

@vjau

Let's say i define a tuple type like this :

type MyTuple = [number, number]

Now when i do this:

let a: MyTuple = [1, 2]
let b: MyTuple = a.slice();

The compiler complains that TS2322: Type 'number[]' is not assignable to type '[number, number]'. Property '0' is missing in type 'number[]'.

I think it should work, slice without argument (or slice(0) or even slice(0,2)) should allow to clone a tuple.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptRevisitAn issue worth coming back to

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions