Skip to content

Type argument inference does not take call's contextual type into account #10245

@zakjan

Description

@zakjan

TypeScript Version: 2.0.0

Code

function map(array: number[]): [number, number][] {
    return array.map((x: number) => [x, x * x]);
}

Expected behavior:
no error

Actual behavior:

error TS2322: 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[]'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.SuggestionAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions