πŸ’™ 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

 

λ°˜μ‘ν˜•