Pages

Topics

Tools

↑↓navigate↵openescclose
All guides

TypeScript Utility Types: Pick, Omit, Partial, and Record Explained

How Pick, Omit, Partial, and Record are built from mapped types: what each preserves, why Omit accepts a typo, how Partial distributes over unions, and the errors each raises.

~4 min readTypeScript
#TypeScript#Generics#Utility Types
Modular TypeScript type blocks being picked, omitted, and assembled into a Record

Pick, Omit, Partial, and Record are not built-in magic; each is a mapped type a few characters long, and almost every surprise they produce is decided by two details of that definition — whether the mapped type is homomorphic over keyof T, and how the key parameter is constrained. Partial<T> is { [P in keyof T]?: T[P] }, so it distributes over unions and maps tuples in place. Omit<T, K> is Pick<T, Exclude<keyof T, K>>, so it does neither and quietly accepts keys that do not exist.

Quick Summary

  • Partial<T> makes every property optional. It is homomorphic, so it keeps readonly, keeps optionality of properties that already had it, and distributes over unions.
  • Pick<T, K> keeps only K, and K must extend keyof T, so an unknown key is a compile error.
  • Omit<T, K> removes K and constrains K to keyof any, so a misspelled key compiles and does nothing.
  • Record<K, T> builds an object type with exactly the keys in K and value type T. It requires every key, and K may be string to produce an index signature.
  • Partial is shallow. Nested objects stay fully required unless a recursive type is written by hand.
  • Omit is not homomorphic, so it does not preserve tuple and array structure, and it does not distribute over unions.

Basic syntax and type signatures

The definitions are short enough to read from lib.es5.d.ts, and reading them answers most questions:

typescript
type Partial<T> = { [P in keyof T]?: T[P] }; type Required<T> = { [P in keyof T]-?: T[P] }; type Pick<T, K extends keyof T> = { [P in K]: T[P] }; type Record<K extends keyof any, T> = { [P in K]: T }; type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

keyof any resolves to string | number | symbol, which is why Record<"a" | "b", V> and Record<string, V> share one definition while Pick<T, "typo"> fails immediately: "typo" is not assignable to keyof T. Omit has no such guard, because its K is only checked against the set of all possible keys, not against the keys of T.

Every one of these is erased at compile time. Pick<User, "id"> and { id: number } are the same type, so the choice between them is about maintenance, not runtime cost.

typescript
interface User { id: number; name: string; email?: string; readonly createdAt: number; } type Preview = Pick<User, "id" | "email" | "createdAt">; // { id: number; email?: string; readonly createdAt: number }

Pick copies the ? and readonly modifiers from the source, so Preview keeps email optional instead of promoting it to a required string | undefined.

The four utilities side by side

UtilityDefinition shapeKey constraintOver a union A | BArrays and tuples
Partial<T>[P in keyof T]?nonedistributes to Partial<A> | Partial<B>element type becomes optional
Pick<T, K>[P in K]K extends keyof Tkeys collapse to keyof A & keyof Btuple structure lost
Omit<T, K>Pick<T, Exclude<keyof T, K>>K extends keyof anyone object of the shared keystuple structure lost
Record<K, T>[P in K]K extends keyof anynot distributive, K is the key setnot applicable

The union column is where most production bugs start. keyof (A | B) is the intersection of the two key sets, so Pick<Shape, "kind"> and Omit<Shape, "kind"> both flatten a discriminated union into one object built from the keys every member shares.

Practical edge cases and deep dives

1. Partial is shallow, so nested settings stay required

A settings type with one nested block is the usual place where Partial<Settings> fails to type-check the object people actually pass:

typescript
interface Settings { theme: "light" | "dark"; notifications: { email: boolean; push: boolean }; } const patch: Partial<Settings> = { theme: "dark", notifications: { email: false }, // error TS2741: Property 'push' is missing in type // '{ email: boolean; }' but required in type '{ email: boolean; push: boolean; }' };

The fix is a recursive mapped type, which must handle arrays explicitly or it will turn every array into an object of numeric keys:

typescript
type DeepPartial<T> = T extends (infer U)[] ? DeepPartial<U>[] : T extends object ? { [P in keyof T]?: DeepPartial<T[P]> } : T;

DeepPartial also drops the homomorphic link to the original type, so readonly survives only where the object type carries it, and explicitly undefined-able properties behave differently under exactOptionalPropertyTypes.

2. Omit accepts a typo, so pin the key

Omit<User, "emial"> compiles and returns all of User. Nothing warns, because "emial" is a valid keyof any. A one-line helper restores the check by inheriting Pick's constraint:

typescript
type StrictOmit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type WithoutEmail = StrictOmit<User, "emial">; // error TS2344: Type '"emial"' does not satisfy the constraint 'keyof User'

The same looseness appears in reverse: Omit<T, keyof T> yields {}, which accepts any object because excess property checks do not apply to an empty target — a valid type and a useless one.

3. Keeping a discriminant while partializing a union

Partial<Shape> distributes across the union, which makes kind optional and breaks narrowing: a value can now have kind: undefined and no usable member.

typescript
type Shape = | { kind: "circle"; radius: number } | { kind: "square"; side: number }; type Draft = Partial<Shape>; // kind is optional on both members type Patch = Partial<Omit<Shape, "kind">> & Pick<Shape, "kind">; // keyof (A | B) is just "kind", so Omit<Shape, "kind"> is {} declare const patch: Patch; if (patch.kind === "circle") { patch.radius; // error TS2339: 'radius' does not exist on type 'Patch' }

Omit here flattens the union before Partial sees it, so Patch only carries the shared keys — kind plus nothing else. To keep per-member optionality, distribute first with a conditional type over the naked type parameter:

typescript
type PartialKeys<T, K extends PropertyKey> = Omit<T, Extract<keyof T, K>> & Partial<Pick<T, Extract<keyof T, K>>>; type DistributedPatch = Shape extends unknown ? PartialKeys<Shape, "radius" | "side"> : never; // { kind: "circle"; radius?: number } | { kind: "square"; side?: number }

Extract<keyof T, K> is what lets one key list serve both members: it resolves to "radius" for the circle and to "side" for the square, so the keyof T constraint on Pick and Omit is satisfied in each branch.

4. Record for exhaustive maps, Partial<Record> for sparse ones

Record<Status, string> demands every status and returns string with no undefined in the type. A Partial<Record<Status, string>> is the sparse version, and the difference is visible at every read:

typescript
type Status = "idle" | "loading" | "error"; const labels: Record<Status, string> = { idle: "Idle", loading: "Loading", error: "Failed" }; const labelsRead: string = labels.idle; const cache: Partial<Record<Status, string>> = {}; const cached: string | undefined = cache.idle; const index: Record<string, string> = {}; const anyKey: string | undefined = index["missing"]; // only with noUncheckedIndexedAccess

The last line is the trap: Record<string, string> describes keys that are assumed present, so without noUncheckedIndexedAccess a lookup returns string and blows up at runtime instead of returning undefined.

Common mistakes and compiler errors

SymptomCauseFix
Type 'string' does not satisfy the constraint 'keyof T' (TS2344)Pick<T, keyof typeof obj> where obj is a plain string[] or the key was widenedpass a literal union or as const
Property is missing in type … but required in type Pick<…>Pick keeps required properties requiredwrap in Partial, or pick fewer keys
A misspelled Omit key compiles and changes nothingK extends keyof anyuse StrictOmit, or satisfies the key list
Nested object still required after PartialPartial is shallowwrite DeepPartial, or partialize the nested type
shape.kind is undefined after partializing a unionPartial distributed over the unionkeep the discriminant with Pick
Omit<Union, K> lost every member but the shared keyskeyof of a union is an intersectiondistribute first with a conditional type
Index access returns string but is undefined at runtimeRecord<string, V> assumes the key existsenable noUncheckedIndexedAccess or use Partial<Record<…>>
Array type lost map after OmitOmit is not homomorphicuse Partial or a mapped type over the array

The rule behind the table is the definition itself: reach for Pick and Partial when the property list must stay honest, and for Omit only when the excluded keys are already typed somewhere, because it is the one utility of the four that cannot tell a typo from a real key.

Try matching browser tools

All tools

Small utilities that fit TypeScript work — they run entirely in this browser tab, so nothing you paste leaves your device.

All TypeScript guides

More in TypeScript

All TypeScript guides

The guides filed next to this one in TypeScript, in library order.