채린씨의 티스토리
[TypeChallenges] 4. Pick (easy) 본문
문제
Implement the built-in Pick<T, K> generic without using it.
Constructs a type by picking the set of properties K from T
For example:
interface Todo {
title: string
description: string
completed: boolean
}
type TodoPreview = MyPick<Todo, 'title' | 'completed'>
const todo: TodoPreview = {
title: 'Clean room',
completed: false,
}
(출처: https://github.com/type-challenges/type-challenges/blob/main/questions/00004-easy-pick/README.md)
나의 풀이
TypeScript의 내장 유틸리티 타입인 Pick을 직접 구현하는 문제였다!
type MyPick<T, K extends keyof T> = {
[Key in K]: T[Key]
}
참고자료
1. 제네릭이란?
https://joshua1988.github.io/ts/guide/generics.html
2. Pick이란?
'FE > TypeScript' 카테고리의 다른 글
[TypeChallenges] 7. Readonly (easy) (0) | 2023.03.24 |
---|---|
[TypeChallenges] 13. Hello World (warm-up) (0) | 2023.03.24 |
Comments