Annotated solution
Published July 27, 2026The solution
type Last<T extends readonly unknown[]> = T extends readonly [...unknown[], infer L] ? L : never
The common wrong answer
type Last<T extends readonly unknown[]> = T[number]
Indexing a tuple with `number` gives the union of *every* element type, so `[1, 2, 3]` yields `1 | 2 | 3`. Position information is lost the moment you index that way.
Line by line
[...unknown[], infer L]A tuple pattern may contain exactly one rest element, and it is allowed to sit at the front. Matched against a fixed-length tuple, the rest absorbs everything except the final slot, which binds to `L`.
: neverThe empty tuple matches nothing — there is no final slot to bind — so the false branch answers with the type that has no values.
Takeaway
A rest element in a tuple pattern does not have to be last. Leading rests are how you reach the end of a tuple without counting your way there.