Omit vs Pick: Choosing the Right Tool
What you'll learn: How to decide whether to include specific properties with Pick or exclude them with Omit for clearer, more maintainable code.
The Decision Point
Both Pick and Omit create new types by selecting properties from an existing type, but they work in opposite directions. The question isn't about capability—you can achieve the same result with either—but about clarity of intent.
When to Use Pick
Use Pick<T, K> when you want to emphasize what you're keeping. This works best when:
- You need only a small subset of many properties
- The selected properties form a meaningful concept together
- You're creating a focused type for a specific use case
type User = {
id: string;
email: string;
password: string;
firstName: string;
lastName: string;
age: number;
role: string;
};
// Clear intent: "public profile data only"
type PublicProfile = Pick<User, 'id' | 'firstName' | 'lastName'>;
When to Use Omit
Use Omit<T, K> when you want to emphasize what you're removing. This works best when:
- You need to exclude only a few sensitive or irrelevant properties
- The remaining properties are the "normal" case
- You're removing specific concerns (like secrets or metadata)
// Clear intent: "everything except sensitive data"
type SafeUser = Omit<User, 'password'>;
The Readability Test
Ask yourself: "What's easier to understand six months from now?" If someone reads Pick<User, 'id' | 'name'>, they know exactly what's included. If they see Omit<User, 'password' | 'ssn'>, they know what's being protected.
Key Takeaway: Choose Pick when the subset tells the story; choose Omit when the exclusions tell the story. Optimize for the reader's understanding of your intent.