diff --git a/00014-easy-first.ts b/00014-easy-first.ts new file mode 100644 index 0000000..5c650ba --- /dev/null +++ b/00014-easy-first.ts @@ -0,0 +1,22 @@ +// ============= Test Cases ============= +import type { Equal, Expect } from './test-utils'; + +type cases = [Expect, 3>>, Expect 123, { a: string }]>, () => 123>>, Expect, never>>, Expect, undefined>>]; + +type errors = [ + // @ts-expect-error + First<'notArray'>, + // @ts-expect-error + First<{ 0: 'arrayLike' }> +]; + +// ============= Your Code Here ============= + +// 判断是否为空数组 +// type First = T extends [] ? never : T[0]; + +// 判断长度是否为 0 +// type First = T['length'] extends 0 ? never : T[0]; + +// 使用 infer 取第零个元素 +type First = T extends [infer F, ...any[]] ? F : never;