Fifth challenge is Length of Tuple
As for First of Array, we can use it for both arrays and tuples, but for tuples you get exact value.
When we distinguished arrays from tuples in Making object out of tuple, we have seen that we can call
['length'] in types which is really convenient. Let's try this:
As usual, for calling tuple methods in types, we need Generic Constrains
For that we used
extends readonly any constrain.
If we try
extends any instead, we would get an error for
The type 'readonly ["tesla", "model 3", "model X", "model Y"]' is 'readonly' and cannot be assigned to the mutable type 'any'
It explains itself: we should expect accepting
To try it out, please have a look at the Playground with tests casestypescript