출처: Type Challenges, https://github.com/type-challenges/type-challenges/blob/main/README.ko.md 14 - First of Array 배열(튜플) `T`를 받아 첫 원소의 타입을 반환하는 제네릭 `First`를 구현하세요. type arr1 = ['a', 'b', 'c'] type arr2 = [3, 2, 1] type head1 = First // expected to be 'a' type head2 = First // expected to be 3 풀이 type First = T extends [infer U, ...unknown] ? U : never `infer`는 `extends`와 함께 쓰이며 타입을 추출해서 뒤에서 다시 ..
출처: Type Challenges, https://github.com/type-challenges/type-challenges/blob/main/README.ko.md 4 - Pick T에서 K 프로퍼티만 선택해 새로운 오브젝트 타입을 만드는 내장 제네릭 Pick을 이를 사용하지 않고 구현하세요. interface Todo { title: string description: string completed: boolean } type TodoPreview = MyPick const todo: TodoPreview = { title: 'Clean room', completed: false, } 풀이 type MyPick = { [Property in K]: T[Property]; } K가 T 타입의 key..
출처: Type Challenges, 13 - Hello World 13 - Hello World Hello, World! Type Challenges에서는 타입 단언(assertion)을 하기 위해 자체적인 타입 시스템을 사용합니다. 이 과제에서는, 아래의 코드를 변경해서 테스트 코드를 통과하세요. (타입 체크 에러 없음). // string이 되어야 합니다. type HelloWorld = any // 아래의 테스트가 통과하도록 만드세요. type test = Expect 풀이 type HelloWorld = string