First of Array
提出詳細
type First<T extends any[]> = T extends [infer Head, ...any[]] ? Head : never
提出日時 | 2024-10-28 01:59:34 |
---|---|
問題 | First of Array |
ユーザー | balckowl |
ステータス | Accepted |
import type { Equal, Expect } from '@type-challenges/utils' type cases = [ Expect<Equal<First<[3, 2, 1]>, 3>>, Expect<Equal<First<[() => 123, { a: string }]>, () => 123>>, Expect<Equal<First<[]>, never>>, Expect<Equal<First<[undefined]>, undefined>>, ] type errors = [ // @ts-expect-error First<'notArray'>, // @ts-expect-error First<{ 0: 'arrayLike' }>, ]