Skip to content

Tuple types get incorrect contextual type #9901

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Taytay opened this issue Jul 22, 2016 · 5 comments
Closed

Tuple types get incorrect contextual type #9901

Taytay opened this issue Jul 22, 2016 · 5 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@Taytay
Copy link

Taytay commented Jul 22, 2016

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.

@mhegazy mhegazy added the Bug A bug in TypeScript label Jul 22, 2016
@mhegazy mhegazy added this to the TypeScript 2.0.1 milestone Jul 22, 2016
@mhegazy mhegazy changed the title Array.concat compile-time error when using it on an array of tuples: "error TS2345: Argument of type '[number[], number[], [number, number]]' is not assignable to parameter of type '[number, number] | [number, number][]'." Tuple types get incorrect contextual type Jul 22, 2016
@Taytay
Copy link
Author

Taytay commented Jul 22, 2016

Thanks @mhegazy

@sandersn
Copy link
Member

sandersn commented Jul 27, 2016

This is caused by removing one of the overloads of concat (the ugly one, with an additional, constrained type parameter). At the time we thought it wouldn't break anything. I'll try to find the discussion from that time, but almost certainly the right fix is to put the other overload back.

@sandersn
Copy link
Member

The break is in #6629 which happened in response to a long discussion in #6594. We didn't see the tuple problem coming during that discussion, though.

@sandersn
Copy link
Member

PR is up at #9997 -- I added an explanation of why this fails there.

@Taytay
Copy link
Author

Taytay commented Aug 2, 2016

TY for the fix!

On Tuesday, August 2, 2016, Nathan Shively-Sanders notifications@github.com
wrote:

Closed #9901 #9901 via
#9997 #9997.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#9901 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABROBWTbzyH1UC7FLX8Np503qAuZuSbWks5qb4c8gaJpZM4JS7ZZ
.

@DanielRosenwasser DanielRosenwasser added the Fixed A PR has been merged for this issue label Aug 2, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

4 participants