TypeScript spread operator for 2 tuple types
15 Apr 2021
Ninth challenge is Concat
Sometimes it's useful to collect 2 tuples' elements in one tuple, like Array.prototype.concat.
Using spread for Tuple types
2 changes were introduced in TypeScript 4.0:
- Variadic Tuple Types
- You can use spread anywhere in a tuple, not just an end
So let's try it all together:
Here we have an error A rest element type must be an array type
, let's add Generic Constrains to allow only arrays:
This is it 🚀
Don't forget to have a look at Playground ⏯
typescript