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
Related utility types
Omit<T, K>
Constructs a type by removing the properties in K from T. Unlike Pick, its K is not constrained to keyof T, so extra keys are silently ignored.
Partial<T>
Constructs a type where every property of T is set to optional. Useful for representing update payloads, patch objects, and configuration overrides where all fields may be omitted.
Record<K, V>
Creates an object type whose keys come from the union K and whose values all have type V. Useful for lookup tables, dictionaries, and enum-keyed maps.
Exclude<T, U>
Filters a union T by removing every member that is assignable to U. Distributes over union members via the conditional type, producing the set-difference T \ U.
Required<T>
Removes optionality from every property of T, producing a type where all fields must be present. The -? mapping modifier strips the ? flag from every key.
← All TS utility types · TypeScript vs JavaScript · any vs unknown vs never