MyOmit<T, K>
MediumP1Coding
Implement the built-in Omit<T, K> generic without using it.
MyOmit<T, K> builds a type from T with the keys in K removed. K must be limited to keys of T.
Tests your type must pass
interface Todo {
title: string
description: string
completed: boolean
}
interface Expected1 {
title: string
completed: boolean
}
interface Expected2 {
title: string
}
type cases = [
Expect<Equal<Expected1, MyOmit<Todo, 'description'>>>,
Expect<Equal<Expected2, MyOmit<Todo, 'description' | 'completed'>>>,
Expect<Equal<Todo, MyOmit<Todo, never>>>,
// @ts-expect-error 'invalid' is not a key of Todo
MyOmit<Todo, 'description' | 'invalid'>,
]Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
TypeScript
Run and Submit type-check your solution against the tests. ⌘Enter runs, ⌘⇧Enter submits.