Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit #429

Open
linjunc opened this issue Jan 28, 2023 · 1 comment
Open

Omit #429

linjunc opened this issue Jan 28, 2023 · 1 comment

Comments

@linjunc
Copy link
Contributor

linjunc commented Jan 28, 2023

实现 TS 中的 Omit 方法

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

type MyOmit<T, K extends keyof T> = {
  [R in keyof T as R extends K ? never: R ]: T[R]
}

type TodoPreview = MyOmit<Todo, 'description' | 'title'>
@Aurora-GSW
Copy link

type MyPick<T, K extends keyof T> = {
    [p in K]:T[p]
}
//实现1
type MyOmit<T, K extends keyof any> = MyPick<T,Exclude<keyof T,K>>

//实现2
type MyOmit<T, K extends keyof any> = {
    [p in Exclude<keyof T,K>]:T[p]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants