TypeScript 4.0
Variadic Tuple Types
Pre 4.0 situation
Consider the following function using Tuples:
The only way to type this in TypeScript used to be:
Post 4.0 situation
-
Tail example
Consider the following example:
TypeScript 4.0 bring 2 changes here.
-
Changes
-
Generic spreads in tuple types
The spreads in tuple type syntax to be generic:
-
Rest elements can occur anywhre in a tuple
Rest elements can occur anywhere in a tuple, not just at the end:
-
-
-
Concat example
Note that in cases when we spread in a type without a known length, the resulting type becomes unbounded as well, and all the following elements factor into the resulting rest element type.
Therefore the
concat()
example can be typed with:
Examples
Parameter annotations
Return type annotation
Optional Parameters
Overloading
This is for documentation purposes but imho just makes things more confusing.
Declaring Functions
Use this to declare function type without providing implementation:
Overloading is supported as well: