What is the Exclude utility type?
Answer
Exclude<T, U> removes from union type T all members that are assignable to U. Implementation: type Exclude<T, U> = T extends U ? never : T — it distributes over the union and replaces matching members with never, which then collapses. Example: type Colors = "red" | "blue" | "green"; type NotBlue = Exclude<Colors, "blue">; — result is "red" | "green". Exclude any object type: type Primitives = Exclude<string | number | boolean | object, object>; — result is string | number | boolean. Compare with Omit: Exclude works on union types (removes union members); Omit works on object types (removes properties). Related: Extract<T, U> is the opposite — keeps only the members of T that ARE assignable to U. Use case: type EventKeys = Exclude<keyof HTMLElement, "style" | "className"> to create a subset of DOM event keys.