-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Closed
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue
Milestone
Description
TypeScript Version: 2.1.1
Code
const a: [number, number, number, number, number, number] = [1,2,3,4,5,6];
const b = a.map(x => x)Expected behavior:
b should have the same type as a, i.e. a tuple of 6 numbers
Actual behavior:
b has the type of a tuple of 5 numbers. Not only is this unexpected, it also doesn't match what happens at runtime where b.length == a.length as expected.
It seems to me that the problem comes from the tuple overloads of map added in #11252.
If I understand this correctly, #5453 would be needed in order to these overloads correctly for the general case.
In the meantime if there was some way of falling back to an array for map on longer tuples, that would work, e.g. adding an overload like this maybe?
map<Q extends [T, T, T, T, T, T], U>(this: Q, callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[];Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issue