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

3 - 实现 Omit #33068

Open
DwayneDuanJY opened this issue Apr 28, 2024 · 0 comments
Open

3 - 实现 Omit #33068

DwayneDuanJY opened this issue Apr 28, 2024 · 0 comments
Labels
3 answer Share answers/solutions to a question zh-CN 简体中文

Comments

@DwayneDuanJY
Copy link

首先Omit<A, B>可以理解为Pick<A, C>,其中B | C exends keyof A。例如A = {a:1, b: 2, c: 3, d: 4} B = 'a'|'b' 那么C = 'c'|'d'
type MyOmit<A, B extends keyof A> = type Pick<A, Exclude<keyof A, B>>
Pick和Exclude也可以自定义实现
type MyPick<A, B extends keyof A> = {[K in B]: A[K]}
type MyExclude<A, B> = A extends B ? never : A

// 你的答案
@DwayneDuanJY DwayneDuanJY added answer Share answers/solutions to a question zh-CN 简体中文 labels Apr 28, 2024
@github-actions github-actions bot added the 3 label Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 answer Share answers/solutions to a question zh-CN 简体中文
Projects
None yet
Development

No branches or pull requests

1 participant