Skip to content

mapping over an array of tuple types does not give the correct type #11312

Closed
@mattyork

Description

@mattyork

TypeScript Version: 2.0.3

Code

The map callback in the code below is the identity function.

let arr: Array<[number, number]> = [[1, 2]]

let mappedArr: Array<[number, number]> = arr.map(([x, y]) => {
    return [x, y];
})

Expected behavior: mappedArr is of type Array<[number, number]>. Compilation works.

Actual behavior: Doesn't work. Error message:

Type 'number[][]' is not assignable to type '[number, number][]'.
  Type 'number[]' is not assignable to type '[number, number]'.
    Property '0' is missing in type 'number[]'.

TypeScript playground link

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions