I tried mapping a TypeScript Tuple into another Tuple using Array.map like so:
const tuple1: [number, number, number] = [1, 2, 3];
const tuple2: [number, number, number] = tuple1.map(x => x * 2);
console.log(tuple2);
But the typescript compiler is telling me this is not possible:
Type 'number[]' is not assignable to type '[number, number, number]'.
Target requires 3 element(s) but source may have fewer.
Is there a clean way to map a tuple into a new tuple without using Array.map or a way to use Array.map that the compiler does understand?
tuple1.map(x => x * 2) as [number, number, number];, but that's not ideal I guess? :)fp-ts. There's a Tuple module where you can doconst z: [number,number,number] = pipe(x, tuple.map(x => x*2))with no problems. Orconst z: [number,number,number] = tuple.map<number>(x => x*2)(x)It's probably done with declare function overloads.