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

43 - Exclude #18522

Closed
mefengl opened this issue Nov 3, 2022 · 3 comments
Closed

43 - Exclude #18522

mefengl opened this issue Nov 3, 2022 · 3 comments
Labels
43 answer Share answers/solutions to a question en in English

Comments

@mefengl
Copy link
Contributor

mefengl commented Nov 3, 2022

// extends can be used in two ways
// one is a real extends
// another is like a ternary expression with the traverse of T, called Distributive Conditional Types
// second one can be used in a fun way, like Flatten
// type Flatten<T> = T extends any[] ? T[number]: T;
type MyExclude<T, U> = T extends U ? never : T
// https://www.typescriptlang.org/docs/handbook/2/conditional-types.html#distributive-conditional-types
@mefengl mefengl added answer Share answers/solutions to a question en in English labels Nov 3, 2022
@github-actions github-actions bot added the 43 label Nov 3, 2022
@mefengl mefengl closed this as completed Nov 6, 2022
@loia5tqd001
Copy link

Distributivity. Indeed a very important concept here.

@f0nar
Copy link

f0nar commented Apr 30, 2023

is it all the time applied only to first generic parameter?

@mwashief
Copy link

mwashief commented May 2, 2023

is it all the time applied only to first generic parameter?

Normally how extends keyword works, it distributes both operands. If you need to prevent distribution any of the operands, then use square brackets. For example- [T] extends U or T extends [U]. Also, [T] extends [U] won't distribute any of the operands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
43 answer Share answers/solutions to a question en in English
Projects
None yet
Development

No branches or pull requests

4 participants