TypeScript 7 reference · Utility Types

TypeScript Omit<Type, Keys> Utility Type

Build a type with all properties of another type except the ones you list. The opposite of Pick.

TypeScript 7 Since 3.5

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Omit<Type, Keys>

Parameters

ParameterDescription
Type The object type to transform.
Keys Property names to remove.

Return value

A type without those properties.

Examples

Remove server-generated fieldsTry it yourself
interface User {
  id: number;
  name: string;
  passwordHash: string;
}
type NewUser = Omit<User, "id" | "passwordHash">;
const signup: NewUser = { name: "Ben" };
console.log(signup);

Output

{ name: 'Ben' }
Inputs without the idTry it yourself
interface Product {
  id: number;
  name: string;
  price: number;
}
type ProductInput = Omit<Product, "id">;
function create(p: ProductInput): Product {
  return { id: 42, ...p };
}
console.log(create({ name: "Mug", price: 12 }));

Output

{ id: 42, name: 'Mug', price: 12 }

Version history

VersionChange
TypeScript 3.5Added

Was this page helpful?