Omit
introduction#
Implement the built-in Omit<T, K> generic without using it.
Constructs a type by picking all properties from T and then removing K
For example
tsinterface Todo {title: stringdescription: stringcompleted: boolean}type TodoPreview = MyOmit<Todo, 'description' | 'title'>const todo: TodoPreview = {completed: false,}
View on GitHubtsinterface Todo {title: stringdescription: stringcompleted: boolean}type TodoPreview = MyOmit<Todo, 'description' | 'title'>const todo: TodoPreview = {completed: false,}
start point#
tsTry/* _____________ Your Code Here _____________ */typeMyOmit <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 ,MyOmit <Todo , 'description'>>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Expected2 ,MyOmit <Todo , 'description' | 'completed'>>>]ÂinterfaceTodo {title : stringdescription : stringcompleted : boolean}ÂinterfaceExpected1 {title : stringcompleted : boolean}ÂinterfaceExpected2 {title : string}
take the challengetsTry/* _____________ Your Code Here _____________ */typeMyOmit <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 ,MyOmit <Todo , 'description'>>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <Expected2 ,MyOmit <Todo , 'description' | 'completed'>>>]ÂinterfaceTodo {title : stringdescription : stringcompleted : boolean}ÂinterfaceExpected1 {title : stringcompleted : boolean}ÂinterfaceExpected2 {title : string}