Last<T>
MediumP2Coding
Implement Last<T>, the type of the last element of a tuple T. For an empty tuple, return never.
Tests your type must pass
type cases = [
Expect<Equal<Last<[2]>, 2>>,
Expect<Equal<Last<[3, 2, 1]>, 1>>,
Expect<Equal<Last<[() => 123, { a: string }]>, { a: string }>>,
Expect<Equal<Last<[]>, never>>,
]Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
TypeScript
Run and Submit type-check your solution against the tests. ⌘Enter runs, ⌘⇧Enter submits.