美文网首页
Challange 1 Pick

Challange 1 Pick

作者: Sommouns | 来源:发表于2022-08-23 10:15 被阅读0次

问题描述

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,
}

Solution

type MyPick<T, K extends keyof T> = {
  [P in K]: T[P]
}

相关文章

网友评论

      本文标题:Challange 1 Pick

      本文链接:https://www.haomeiwen.com/subject/uzzwgrtx.html