/*
3 - Omit<T, K>
-------
by Anthony Fu (@antfu) #medium #union #built-in
### Question
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
```ts
interface Todo {
title: string
description: string
completed: boolean
}
type TodoPreview = MyOmit<Todo, 'description' | 'title'>
const todo: TodoPreview = {
completed: false,
}
View on GitHub: https://tsch.js.org/3 */
/* _____________ Your Code Here _____________ */
type MyOmit<T, K> = any
/* _____________ Test Cases _____________ */ import { Equal, Expect } from '@type-challenges/utils'
type cases = [ Expect<Equal<Expected1, MyOmit<Todo, 'description'>>>, Expect<Equal<Expected2, MyOmit<Todo, 'description' | 'completed'>>> ]
interface Todo { title: string description: string completed: boolean }
interface Expected1 { title: string completed: boolean }
interface Expected2 { title: string }
/* _____________ Further Steps _____________ / /
Share your solutions: https://tsch.js.org/3/answer View solutions: https://tsch.js.org/3/solutions More Challenges: https://tsch.js.org */
- Diff 타입 예제에서 영감을 얻었다. Diff 에서 우선 조건부 타입을 이용해서 다른 프로퍼티 들을 추출한다.
- 그런 다음 뽑혀진 키들을 맵핑 타입을 이용해서 새로운 객체 형태를 만든다.
```tsx
type Diff<T, U> = T extends U ? never : T;
type MyOmit<T, K extends keyof T> = {
[key in Diff<keyof T, K>]: T[key]
}