Exclude
Problem - On Github
Create the inbuilt Exclude type. It takes two parameters - the first is a union type, the second a type or union type to exclude from the initial union type.
Out initial type given by the puzzle creator is
type MyExclude<T, U> = any
Solution
This one is a bit of an easier puzzle. There really is just one thing that needs to be done - and that is to see if T
is a part of U
, and if it is we want to say it is never
instead to exclude it.
type MyExclude<T, U> = T extends U ? never : T;
What to read more? Check out more posts below!