type-challenges / type-challenges

Collection of TypeScript type challenges with online judge

Home Page:https://tsch.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

14 - First of Array

kukjun opened this issue · comments

// extends가 조건부 타입으로 쓰임 T extends A ? B:C -> T가 A이면, B. 아니면 C
// 조건부 타입 안에서 infer 키워드를 이용한 타입 추론 가능
// 타입 추론에 있어서 infer 키워드를 안쓰고는 타입을 정의할 수 없으므로 infer를 꼭 사용해야 함
type First<T extends any[]> = T extends [infer P, ...any[]] ? P : never