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[];
TypeScript Version: 2.1.1
Code
Expected behavior:
bshould have the same type asa, i.e. a tuple of 6numbersActual behavior:
bhas the type of a tuple of 5numbers. Not only is this unexpected, it also doesn't match what happens at runtime whereb.length == a.lengthas expected.It seems to me that the problem comes from the tuple overloads of
mapadded 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?