Skip to content
Onsite

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

TypeScript
Run and Submit type-check your solution against the tests.