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

#00043 exclude #7

Open
pkc918 opened this issue Aug 10, 2023 · 0 comments
Open

#00043 exclude #7

pkc918 opened this issue Aug 10, 2023 · 0 comments

Comments

@pkc918
Copy link
Owner

pkc918 commented Aug 10, 2023

问题

type Result = MyExclude<'a' | 'b' | 'c', 'a'> // 'b' | 'c'

不使用 exclude 并实现其效果

答案

type MyExclude<T, U> = T extends U ? never : T

讲解

exclude的作用就是,排除U类型后,T剩下的类型,所以刚好使用 extends 做条件判断

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

1 participant