Omit and Pick are some of the most loved utility types in TypeScript. They let you create new types by excluding or selecting specific properties from an existing type. However, when you use them with union types, their behavior can be misleading - and in some cases, break your type expectations type Employee = { id: string name: string job_name: string } type Customer = { id: string name: string company: string } type Person = Employee | Customer ❌ Problem: Using Omit Directly Suppose you want to remove the id field from all personas: type PersonWithoutId = Omit

May 7, 2025 - 08:51
 0

Omit and Pick are some of the most loved utility types in TypeScript. They let you create new types by excluding or selecting specific properties from an existing type.
However, when you use them with union types, their behavior can be misleading - and in some cases, break your type expectations

type Employee = {
 id: string
 name: string
 job_name: string
}
type Customer = {
 id: string
 name: string
 company: string
}
type Person = Employee | Customer

❌ Problem: Using Omit Directly
Suppose you want to remove the id field from all personas:

type PersonWithoutId = Omit