Q27: How do `Exclude<T, U>`, `Extract<T, U>`, and `NonNullable<T>` work?

Difficulty:MediumTopic:Utility Types

These utility types operate over union types:

  • Exclude<Union, ExcludedMembers>: Removes matching members from a union.
  • Extract<Union, ExtractedMembers>: Keeps only matching members from a union.
  • NonNullable<T>: Excludes null and undefined from a union type.
Key Takeaways
  • Operate over union types via distributive conditional logic.