๋ฐ์ํ
๋ฌธ์
T
์์ K
ํ๋กํผํฐ๋ง ์ ํํด ์๋ก์ด ์ค๋ธ์ ํธ ํ์
์ ๋ง๋๋ ๋ด์ฅ ์ ๋ค๋ฆญ Pick<T, K>
์ ์ด๋ฅผ ์ฌ์ฉํ์ง ์๊ณ ๊ตฌํํ์ธ์.
์์:
interface Todo {
title: string
description: string
completed: boolean
}
type TodoPreview = MyPick<Todo, 'title' | 'completed'>
const todo: TodoPreview = {
title: 'Clean room',
completed: false,
}
ํ์ด
type MyPick<T, K extends keyof T> = {[key in K]: T[key]};
์ถ์ฒ
https://github.com/type-challenges/type-challenges/blob/main/questions/00004-easy-pick/README.ko.md
๋ฐ์ํ
'๐ Typescript > type-challenges' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[TS] type-challenges: 18. Length of Tuple (0) | 2023.07.05 |
---|---|
[TS] type-challenges: 14. First of Array (0) | 2023.07.04 |
[TS] type-challenges : 11. Tuple to Object (0) | 2023.07.03 |
[TS] type-challenges : 7. Readonly (0) | 2023.06.28 |
[TS] type-challenges : 13. Hello World (0) | 2023.06.28 |