首页 > 其他分享 >[Typescript Challenges] 1. Easy - Pick

[Typescript Challenges] 1. Easy - Pick

时间:2022-08-31 15:37:54浏览次数:54  
标签:Typescript string title completed Challenges boolean Easy interface type

For example:

interface Todo {
  title: string
  description: string
  completed: boolean
}

type TodoPreview = MyPick<Todo, 'title' | 'completed'>

const todo: TodoPreview = {
    title: 'Clean room',
    completed: false,
}
/* _____________ Test Cases _____________ */
import type { Equal, Expect } from '@type-challenges/utils'

type cases = [
  Expect<Equal<Expected1, MyPick<Todo, 'title'>>>,
  Expect<Equal<Expected2, MyPick<Todo, 'title' | 'completed'>>>,
  // @ts-expect-error
  MyPick<Todo, 'title' | 'completed' | 'invalid'>,
]

interface Todo {
  title: string
  description: string
  completed: boolean
}

interface Expected1 {
  title: string
}

interface Expected2 {
  title: string
  completed: boolean
}

标签:Typescript,string,title,completed,Challenges,boolean,Easy,interface,type
From: https://www.cnblogs.com/Answer1215/p/16643257.html

相关文章