-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Open
Description
43 - Exclude
Exclude is a very fundamental type to have in your toolbelt in regular day-to-day TypeScript development. It's probably the most re-used utility type in all of the challenges that come, so it's really worthwhile to get familiar with it.
🎥 Video Explanation
🔢 Code
import type { Equal, Expect } from "./test-utils";
type A1 = MyExclude<"a" | "b" | "c", "a">;
type B1 = "b" | "c";
type C1 = Expect<Equal<A1, B1>>;
type A2 = MyExclude<"a" | "b" | "c", "a" | "b">;
type B2 = "c";
type C2 = Expect<Equal<A2, B2>>;
type A3 = MyExclude<
string | number | (() => void),
Function
>;
type B3 = string | number;
type C3 = Expect<Equal<A3, B3>>;
// ============= Your Code Here =============
type MyExclude<T, U> = T extends U ? never : T;
// ================== NOPE ==================
// creates an object type
// when what we want is type unions
type Nope0<T, U> = {
[P in keyof T as P & U]: T[P];
};➕ More Solutions
For more video solutions to other challenges: see the umbrella list! #21338
Metadata
Metadata
Assignees
Labels
No labels