TypeScript Utility Types
Exclude<T, U> — filter union members out
Exclude distributes over T and removes constituents assignable to U. It filters complete union members, not substrings or arbitrary portions of a broad primitive. For example, Exclude<string, "draft"> is still string. Exclusion is based on assignability, so a structurally compatible object type can also be removed. Example output: "review". Verified with strict TypeScript 5.8.3, ES2022 and Node.js 22.16.0. This utility affects static typing; no runtime validation or transformation is supplied by the type itself.
Formal Syntax & Structure
typescript syntaxtypescript
Exclude<T, U>Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| T | type parameter | Union or source type to filter. |
| U | type parameter | Type against which each constituent is tested. |
Working Example
Example Snippettypescript
type Status = "draft" | "review" | "published";type Active = Exclude<Status, "draft">;const status: Active = "review";console.log(status);