How to merge tuples together? I need to add one tuple after end of another like below.
type MergeTuple<A extends any[], B extends any[]> = [...A, ...B];
Only thing that works is this:
type MergeTuple<A extends any[], B extends any[]> = [A[0], B[0]];
But that works with static count of items
MergeTuple<['a'], ['b']> // is ['a', 'b']
Not working for this
MergeTuple<['a', 'b'], ['c']> // is ['a', 'c'] expected ['a', 'b', 'c']
Concatenating Tuples in TS is currently just possible with very ugly workarounds.
Here is how one library does it
You don't want to do that yourself. Ask yourself if you really need that, and if the answer is yes, do yourself the favor and use a type library like typescript-tuple.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With