TypeScript
/Intermediate
Omit<T, Keys>
Definition
A utility type that constructs a new type by starting with an existing type (`T`) and removing a specific set of properties (`Keys`).
Explain Like I'm New
The opposite of `Pick`. If a buffet has 50 dishes, `Pick` is naming the 2 dishes you want. `Omit` is telling the chef: 'Give me literally everything on the table EXCEPT the tomatoes and onions.'
Real World Example
Creating a type for a 'Create User' form payload. The database `User` type has an `id` and `createdAt` date. The user cannot submit these; the database generates them. So the payload type is `Omit<User, 'id' | 'createdAt'>`.
Common Use Cases
- •Form payload typing (removing DB-generated fields)
- •Removing sensitive data (passwords) from types
Interactive Example
Loading Code Playground...
Interview Questions
basic
- When should you use `Omit` instead of `Pick`?
intermediate
- Does `Omit` throw an error if you omit a key that doesn't exist?