Skip to content
jshacks.dev
TypeScript

The Omit Utility Type in TypeScript, With Examples

Omit builds a type by dropping named properties from another. See its definition, why it ignores typos, how unions break it and when Pick is safer.

7 min read
Summarize in AI
Flat illustration of an editor window full of code, with the TypeScript, Vite and JavaScript logos.

Omit<T, K> creates a type with every property of T except the ones named in K. It is the utility you reach for when you want most of a type and need to remove a few fields: the id and timestamps that a database fills in, the password hash that must never leave the server, the props that a wrapper component sets for you. Because the new type is derived from the original, it follows the original when new fields are added. That is its strength and also its risk, and this post covers both. It uses TypeScript 6.x, and the reference is the Omit entry in the utility types page.

The basic idea

Pass the source type and a string literal or a union of string literals.

basic.tsTypeScript
interface User {
  id: number;
  name: string;
  email: string;
  passwordHash: string;
}

type PublicUser = Omit<User, "passwordHash">;

const user: PublicUser = { id: 1, name: "Ada", email: "[email protected]" };

console.log(user);
Text
{ id: 1, name: 'Ada', email: '[email protected]' }

PublicUser has id, name and email, each with the type it has in User. To remove several properties, pass a union: Omit<User, "passwordHash" | "email">. The result is a plain object type, so you can use it for parameters, return types, props and anything else that takes a type.

How it is defined

Omit is not a primitive of the compiler. It is built from two other utilities that you can read in the standard library, and the definition explains most of its quirks.

my-omit.tsTypeScript
type MyOmit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>;

interface Point {
  x: number;
  y: number;
  z: number;
}

const flat: MyOmit<Point, "z"> = { x: 1, y: 2 };

console.log(flat);
Text
{ x: 1, y: 2 }

Read it from the inside out. keyof T is the union of all key names of T. Exclude<keyof T, K> removes the names you listed from that union, and Pick then builds an object type from what is left. If you want the details of the two building blocks, the Pick and Exclude posts on this site cover them, and the mapped types page explains the machinery underneath.

Omit does not check its keys

The constraint on K is keyof any, which is string | number | symbol. That is looser than the keyof T constraint that Pick uses, so a key that does not exist on the type is accepted without a word.

unknown-key.tsTypeScript
interface User {
  id: number;
  name: string;
}

type Same = Omit<User, "age">;

const u: Same = { id: 1, name: "Ada" };

console.log(u);
Text
{ id: 1, name: 'Ada' }

There is no error, and Same is identical to User. This looks like a small thing until a refactor. Suppose User has a field passwordHash and a type says Omit<User, "passwordHash">. Someone renames the field to hash. The Omit still compiles, because it never promised that the key exists, and the renamed field is now exposed in a type that was meant to hide it. Pick<User, "name"> would have failed on a rename, because its constraint is strict.

The language team kept the loose constraint on purpose, because it lets you write Omit over unions of types that do not share all keys. If you want the strict behavior, write your own helper.

strict-omit.tsTypeScript
type StrictOmit<T, K extends keyof T> = Omit<T, K>;

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

type Bad = StrictOmit<User, "age">;
Text
strict-omit.ts(8,29): error TS2344: Type '"age"' does not satisfy the constraint 'keyof User'.

The helper costs one line and turns silent typos into compile errors. Many codebases put it in a shared types.ts file and ban the bare Omit for object types with a lint rule.

What the compiler rejects

Using a property that you removed is an error, and it is the check that makes the type useful.

omitted.tsTypeScript
interface User {
  id: number;
  name: string;
  email: string;
}

function show(user: Omit<User, "email">): string {
  return `${user.id} ${user.email}`;
}
Text
omitted.ts(7,29): error TS2339: Property 'email' does not exist on type 'Omit<User, "email">'.

A function that takes Omit<User, "email"> states that it does not read the email, and the compiler enforces that in the body. Callers can still pass a full User, because an object with extra properties is assignable to a type with fewer.

Modifiers are preserved

Because Omit ends in Pick, which is a homomorphic mapped type, the readonly and optional markers of the remaining properties are kept.

modifiers.tsTypeScript
interface Account {
  readonly id: number;
  nickname?: string;
  balance: number;
}

type Header = Omit<Account, "balance">;

const header: Header = { id: 7 };

header.id = 8;
Text
modifiers.ts(11,8): error TS2540: Cannot assign to 'id' because it is a read-only property.

The literal without nickname is accepted, and the assignment to id fails. If you need different modifiers, combine Omit with Partial or Required, or use a mapped type with a -readonly modifier.

Omit and union types

This is the pitfall that surprises people most. keyof of a union is the set of keys that every member has, so Omit over a union first collapses it into a single object type with the shared keys only.

union.tsTypeScript
interface Circle {
  kind: "circle";
  radius: number;
  color: string;
}

interface Square {
  kind: "square";
  size: number;
  color: string;
}

type Shape = Circle | Square;

type Styled = Omit<Shape, "kind">;

const s: Styled = { color: "red" };

// @ts-expect-error radius and size no longer exist on Styled
const c: Styled = { color: "red", radius: 2 };

console.log(s);
Text
{ color: 'red' }

Styled has only color, because color is the only key besides kind that both shapes share. The variant specific fields radius and size are gone, and so is the discriminated union that made Shape useful. The fix is a distributive version, which applies Omit to each member separately.

distributive.tsTypeScript
interface Circle {
  kind: "circle";
  radius: number;
  color: string;
}

interface Square {
  kind: "square";
  size: number;
  color: string;
}

type Shape = Circle | Square;

type DistributiveOmit<T, K extends PropertyKey> = T extends unknown
  ? Omit<T, K>
  : never;

type Fixed = DistributiveOmit<Shape, "kind">;

const r: Fixed = { color: "red", radius: 2 };
const q: Fixed = { color: "blue", size: 3 };

console.log(r, q);
Text
{ color: 'red', radius: 2 } { color: 'blue', size: 3 }

The conditional type T extends unknown ? ... : never distributes over a naked type parameter, so each member of the union is processed alone and the results are joined again. The conditional types handbook page documents that behavior.

Practical patterns

The most common use is a creation payload. A record has an id and timestamps that the server assigns, and the client should not send them.

create.tsTypeScript
interface Todo {
  id: number;
  title: string;
  done: boolean;
  createdAt: string;
}

type NewTodo = Omit<Todo, "id" | "createdAt">;

function create(input: NewTodo): Todo {
  return { ...input, id: 1, createdAt: "2026-01-01" };
}

console.log(create({ title: "Write post", done: false }));
Text
{ title: 'Write post', done: false, id: 1, createdAt: '2026-01-01' }

When Todo gains a field such as priority, NewTodo gains it too, and create fails to compile until the new field is handled. That automatic propagation is the reason to prefer Omit here over a hand written second interface.

The second pattern is component props. A wrapper around a native element often wants to accept every prop of the element except the one it sets itself, for example Omit<ComponentProps<"input">, "type">. The third is extending an interface with a changed property. An interface cannot redeclare a property with an incompatible type, so you drop the old one and add the new one: interface Row extends Omit<Base, "date"> { date: Date }.

Omit does not change the data

Like every utility type, Omit exists only at compile time. An object with the omitted property is still assignable, and the property is still there when the object is serialized.

leak.tsTypeScript
const full = { id: 1, name: "Ada", passwordHash: "change-me" };

const pub: Omit<typeof full, "passwordHash"> = full;

console.log(pub);

const { passwordHash, ...rest } = full;

console.log(rest);
Text
{ id: 1, name: 'Ada', passwordHash: 'change-me' }
{ id: 1, name: 'Ada' }

The first log shows the leak: the variable has the narrower type, but the value is the same object. The second shows the fix, which is to build a new object with rest syntax or to copy the fields by name. Treat Omit as a statement about what code may read, and treat the copy as the thing that protects the data.

Omit versus Pick

Pick lists what to keep and Omit lists what to remove. The two give the same type today when the lists are complements, and they diverge when the source type grows. A new field is excluded from a Pick result and included in an Omit result. For a shape that crosses a trust boundary, such as an API response, the explicit list of Pick is the safer default, because a new sensitive field stays out until someone adds it. For a payload derived from a record, where you want everything except a few generated fields, Omit is shorter and follows the record.

When not to use Omit

If you remove most of the properties, Pick is shorter and clearer. If the result has its own meaning in your domain, write a named interface, since the two types may need to change separately. If the source is a union, use a distributive version or the result will be wrong. And if the keys must exist, use the strict helper from above, because the built in utility will not tell you when they stop existing.

Share

Keep reading

Flat illustration of an editor window full of code, with the TypeScript, npm and Node.js logos.
TypeScript

Type Inference in TypeScript

TypeScript works out most types for you. Learn how inference treats let and const, arrays, return values and callbacks, and when to write a type yourself.

7 min read
Flat illustration of an editor window full of code, with the TypeScript, Node.js, npm, Vite and JavaScript logos.
TypeScript

What Is TypeScript, and Why Use It?

TypeScript adds static types to JavaScript and checks them before your code runs. Learn what it is, what it catches, what it costs and when to use it.

6 min read

Get new posts by email

We send one email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.