On this page
  1. Extract
  2. Syntax & Overview
  3. Notes & Pitfalls
  4. Example

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

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