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
Syntax
Omit<Type, Keys>
Parameters
| Parameter | Description |
|---|---|
Type |
The object type to transform. |
Keys |
Property names to remove. |
Return value
A type without those properties.
Examples
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' }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
| Version | Change |
|---|---|
| TypeScript 3.5 | Added |
Related
Pick<Type, Keys>· Build a type from just some properties of another type. Handy for API responses and props that need a subset.Exclude<UnionType, ExcludedMembers>· Remove members from a union type. Exclude<'a' | 'b' | 'c', 'a'> is 'b' | 'c'.- TypeScript Utility Types · tutorial