๐Ÿ’™ Typescript/type-challenges

[TS] type-challenges : 4. Pick

์„ ๋‹ฌ 2023. 6. 28. 23:26
๋ฐ˜์‘ํ˜•

๋ฌธ์ œ

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

 

GitHub - type-challenges/type-challenges: Collection of TypeScript type challenges with online judge

Collection of TypeScript type challenges with online judge - GitHub - type-challenges/type-challenges: Collection of TypeScript type challenges with online judge

github.com

 

๋ฐ˜์‘ํ˜•

'๐Ÿ’™ 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