Pick and Omit

Pick and Omit for selecting or removing object keys, including the constraint difference when a key does not exist.

テーマページの本文は現在英語です。

Pick and Omit build a new object type from an existing one by keeping or removing keys. They are compile-time mapped types, not runtime functions that copy or delete fields on a value.

The two helpers are not symmetric. Pick requires every listed key to exist on the source type. Omit is defined as Pick<T, Exclude<keyof T, K>> and its second parameter is only constrained to keyof any, so a typo in a key is silently ignored.

Examples were checked with TypeScript 5.9.3 using tsc --strict. See the TypeScript handbook for the complete utility-type catalog.

TypeScript reference overview →

API index

APISummary
Pick, OmitKeep or remove properties from an object type by key. Pick rejects keys that are not on T; Omit does not.

Pick and Omit

Pick<T, K> keeps only the listed keys. K must extend keyof T, so Pick<User, "country"> is a type error when User has no country field. Omit<T, K> keeps the rest. Omit<User, "country"> is allowed and is the same type as User, which makes a misspelled key easy to miss.

Both operations are shallow. They change which top-level properties are present, not the types of nested objects.

Pick, Omit

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

type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

Keep or remove properties from an object type by key. Pick rejects keys that are not on T; Omit does not.

Type parameterDescription
TThe source object type.
KFor Pick, a union of keys that must already exist on T. For Omit, a union of keys to remove; keys that are not on T are ignored.

Produces: A new object type with the selected or remaining properties. No runtime object is created.

Type errors

  • type error — Pick<T, K> is an error when K is not assignable to keyof T. Accessing a property that was omitted, or a property that was never picked, is also an error.
  • Omit arrived in TypeScript 3.5. The declaration above is from TypeScript 5.9.3.
  • Use Pick when you want the compiler to tell you that a key does not exist. Use Omit when you want to subtract keys, and double-check the spelling.
typescript
type User = { name: string; age?: number; city: string };

type NameAndAge = Pick<User, "name" | "age">;
const picked: NameAndAge = { name: "Ada", age: 36 };
// @ts-expect-error Pick does not include city
picked.city = "Paris";
// @ts-expect-error every key passed to Pick must exist on the source type
type BadPick = Pick<User, "country">;

type WithoutCity = Omit<User, "city">;
const omitted: WithoutCity = { name: "Ada" };
// @ts-expect-error city was omitted
omitted.city = "Paris";

type StillHasCity = Omit<User, "country">;
const kept: StillHasCity = { name: "Ada", city: "Paris" };

console.log(picked.name, omitted.name, kept.city);

Expected output

Ada Ada Paris

Related: Official Pick, Official Omit

Official documentation →