Intermediate
Challenge: TupleToUnion and Last
Write TupleToUnion<T> (the union of a tuple's element types) and Last<T> (the type of its last element, or never for an empty tuple).
TupleToUnion<['a', 'b', 3]> is 'a' | 'b' | 3. Last<[1, 2, 3]> is 3, and Last<[]> is never. TupleToUnion must also accept readonly tuples, and must reject something that is not an array, like string.
What Check tests
- Your code has no type errors
- TupleToUnion accepts a readonly tuple
- TupleToUnion rejects a type that is not an array
- Last works with one element
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
Runs in your browser. Your code is saved here.
Press Run to see the page.
Console
Nothing printed yet.