Last of Array
提出詳細
type LengthMinusOne<T extends any[]> = T extends [] ? -1 : T extends [infer _, ...infer Rest] ? Rest['length'] : never; type Last<T extends any[]> = T[LengthMinusOne<T>];
提出日時 | 2023-08-10 02:17:15 |
---|---|
問題 | Last of Array |
ユーザー | tekihei2317 |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<Last<[3, 2, 1]>, 1>>, Expect<Equal<Last<[() => 123, { a: string }]>, { a: string }>>, ]