Omit Utility Type
What
The Omit<T, K> utility type is the opposite of Pick. It creates a new type by taking an existing type (T) and removing specific keys (K).
How
You provide the original type and a union of the keys you want to exclude:
interface User {
id: string;
username: string;
passwordHash: string; // Sensitive data
}
// All properties except passwordHash are included
type PublicUser = Omit<User, "passwordHash">;
Why
Omit is a powerful tool for data security and cleanup. It allows you to define a “private” database model and easily derive a “public” version by stripping away sensitive or unnecessary fields, ensuring that those fields are never accidentally leaked to other parts of your system.
Summary
Use Omit<T, K> to create safe versions of your types by removing properties that shouldn’t be exposed.