Skip to content

Tuple types get incorrect contextual type #9901

Closed
@Taytay

Description

@Taytay

TypeScript Version:

$ tsc --version
Version 2.0.0

Code

// concat-bug.ts
var a : Array<[number, number]>= [[1, 2]];

// Typescript detects these first two tuples as arrays of numbers (`number[]`) instead of `[number, number]`
a.concat([[3, 4], [5, 6], [7, 8]]);

Expected behavior:
No compile errors. (It works in the 1.8 playground)

Actual behavior:

$ tsc concat-bug.ts
concat-bug.ts(4,10): error TS2345: Argument of type '[number[], number[], [number, number]]' is not assignable to parameter of type '[number, number] | [number, number][]'.
  Type '[number[], number[], [number, number]]' is not assignable to type '[number, number][]'.
    Types of property 'pop' are incompatible.
      Type '() => number[] | [number, number]' is not assignable to type '() => [number, number]'.
        Type 'number[] | [number, number]' is not assignable to type '[number, number]'.
          Type 'number[]' is not assignable to type '[number, number]'.
            Property '0' is missing in type 'number[]'.

Note that the 3rd parameter is correctly detected as a tuple, but the first two are detected as arrays of numbers.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions