object-transforms

Pick<T, K>

Builds a new type containing only the properties from T whose keys are in the union K. Ideal for narrowing large interfaces to the subset a function or component actually needs.

type Pick<T, K extends keyof T> = { [P in K]: T[P] }

Usage patterns

Pattern Purpose
Pick<T, 'a' | 'b'> Select exactly the named keys
Pick<T, keyof U> Pick keys defined by another type
Pick<T, K> & Omit<T, K> Round-trips back to T — Pick and Omit are complements
Pick<Required<T>, K> Combine with Required to force selected fields

Examples

interface User { id: number; name: string; email: string; password: string }
type PublicUser = Pick<User, 'id' | 'name' | 'email'>;

PublicUser excludes password — commonly used to strip sensitive fields

type ButtonProps = Pick<HTMLButtonElement, 'disabled' | 'onclick'>;

Reuse only two DOM properties without re-declaring their types

type Coords = Pick<{ x: number; y: number; z: number }, 'x' | 'y'>;

Result: { x: number; y: number }

type Foo = Pick<User, 'unknown'>; // Error

K must extend keyof T — invalid keys are caught immediately

Gotcha

K is constrained by `extends keyof T`, so misspelled keys error at the type site. Pick is the complement of Omit: `Pick & Omit` equals T.

Related utility types

← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never