Fix my mental model for this Exclude reimplementation in TypeScript

Viewed 9

I try to implement a custom Exclude utility type, in this TS challenge :

I don't really understand a way of using a generic in TS. Can you explain to me this magic?

For context, Exclude utility type makes this :

Exclude<"a" | "b" | "c", "a"> => "b" | "c"

And the solution of the challenge is :

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

What I don't understand is that when I declare MyExclude<"a" | "b" | "c", "a">, in my comprehension I bound the T generic parameter to this exact type "a" | "b" | "c".

So how in the ternary operator T can possibly be "b" | "c" afterwards?

0 Answers
Related