Codectionary / Developer documentation / TypeScript

Pick<T> and Omit<T>

Pick<T, Keys> constructs a new type by selecting only the specified properties from T. Omit<T, Keys> does the reverse, constructing a new type with all properties of T except the specified ones. Both are extremely common for deriving smaller, focused types from a larger base type without duplicating the definition.

Syntax

Pick<Type, Keys>
Omit<Type, Keys>

Examples

Pick<T> - Selecting Specific Properties

Deriving a smaller type with just the fields you need.

interface User {
  id: number;
  name: string;
  email: string;
  password: string;
}

type UserPreview = Pick<User, "id" | "name">;
// Equivalent to: { id: number; name: string }

const preview: UserPreview = { id: 1, name: "Alice" };

Omit<T> - Excluding Specific Properties

A very common real-world case: deriving a "safe" type that excludes sensitive fields.

type PublicUser = Omit<User, "password">;
// Equivalent to: { id: number; name: string; email: string }

function sendToClient(user: User): PublicUser {
  const { password, ...publicUser } = user;
  return publicUser; // password is excluded, matching the PublicUser type
}

Best practices

  • Use Pick<T> when you need a smaller type with just a few known fields from a larger interface, keeping both types in sync automatically
  • Use Omit<T> especially for excluding sensitive fields (like password or internal IDs) when defining what data is safe to send to a client
  • Derive types with Pick/Omit rather than manually rewriting a near-duplicate interface - the derived type stays in sync if the base type changes
  • Chain Pick and Omit with other utility types (like Partial<Omit<User, "id">>) for precise, composed type transformations

At a glance

Purpose
Static types for JavaScript
File extension
.ts ยท .tsx
Runs in
Compiled to JavaScript
Usually used with
JavaScript and its ecosystem

Specifications & further reading

Related TypeScript documentation