Pick
#
introductionImplement the built-in Pick<T, K>
generic without using it.
Constructs a type by picking the set of properties K
from T
For example
ts
interface Todo {title: string;description: string;completed: boolean;}type MyPick<T, K> = any;type TodoPreview = MyPick<Todo, 'title' | 'completed'>;const todo: TodoPreview = {title: 'Clean room',completed: false,};
View on GitHubts
interface Todo {title: string;description: string;completed: boolean;}type MyPick<T, K> = any;type TodoPreview = MyPick<Todo, 'title' | 'completed'>;const todo: TodoPreview = {title: 'Clean room',completed: false,};
#
start pointtsTry
/* _____________ Your Code Here _____________ */typeMyPick <T ,K > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Expected1 ,MyPick <Todo , 'title'>>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Expected2 ,MyPick <Todo , 'title' | 'completed'>>>];ÂinterfaceTodo {title : string;description : string;completed : boolean;}ÂinterfaceExpected1 {title : string;}ÂinterfaceExpected2 {title : string;completed : boolean;}
Take the ChallengetsTry
/* _____________ Your Code Here _____________ */typeMyPick <T ,K > = any;Â/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Expected1 ,MyPick <Todo , 'title'>>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Expected2 ,MyPick <Todo , 'title' | 'completed'>>>];ÂinterfaceTodo {title : string;description : string;completed : boolean;}ÂinterfaceExpected1 {title : string;}ÂinterfaceExpected2 {title : string;completed : boolean;}