On this page
Extract
Prev: `Exclude` | Up: union_and_nullability | Next: `NonNullable`
Rel: union_and_nullability, Conditional & Mapped Types
Ref: TypeScript Docs — Utility Types
Tags: #public #web #typescript #utility-types #union_and_nullability #tier/standard
Syntax & Overview
Extract<Type, Union>
Keeps only union members assignable to Union.
Notes & Pitfalls
- Keeps only union members assignable to
U: Ideal for narrowing discriminated unions to one branch.
Example
type Event = { type: "open"; url: string } | { type: "close"; code: number };
type CloseEvent = Extract<Event, { type: "close" }>; // { type: "close"; code: number }
Linked from
Related notes
- tuts/typescript/utility_types/union_and_nullability/Exclude Linked here; links to this page; shared tags: #tier, #typescript, #web
- tuts/typescript/utility_types/union_and_nullability/NonNullable Linked here; links to this page; shared tags: #tier, #typescript, #web
- tuts/typescript/utility_types/union_and_nullability Linked here; links to this page; shared tags: #typescript, #web
- tuts/typescript/type_system/conditional_and_mapped_types Linked here; shared tags: #typescript, #web
- tuts/typescript/builtins/any shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/as_const shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/asserts shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/enum shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/infer shared tags: #tier, #typescript, #web
- tuts/typescript/builtins/is shared tags: #tier, #typescript, #web