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

myExclude #344

Open
FailurMan opened this issue Dec 30, 2022 · 1 comment
Open

myExclude #344

FailurMan opened this issue Dec 30, 2022 · 1 comment

Comments

@FailurMan
Copy link
Contributor

//使用ts实现exclude方法
type MyExclude<T, U> = T extends U ? never : T;

type eg = MyExclude<string | number | boolean, number | boolean>;
@gswysy
Copy link

gswysy commented Mar 14, 2024

//extends前面T是泛型会进行分发
type MyExclude<T, V> = T extends V ? never : T;

//相当于 ('a' extends 'a'|'c' ? never : 'a') | ('b' extends 'a'|'c' ? never : 'b')
//普通字面量不会进行分发  'a'|'b' extends 'a'|'c' ? 1 : 2   //2
type a = MyExclude<"a" | "b", "a" | "c">;

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