Skip to main content
Practice Problems

Utility type omit in TypeScript

What is Omit<T, K>?

Omit<T, K> constructs a type by picking all properties from T and then removing the keys specified in K. It's the opposite of Pick<T, K>.


Basic Usage

typescript
interface User { id: string; name: string; email: string; password: string; createdAt: Date; } // Remove sensitive fields type PublicUser = Omit<User, "password">; // { id: string; name: string; email: string; createdAt: Date } // Remove multiple fields type UserPreview = Omit<User, "password" | "createdAt">; // { id: string; name: string; email: string }

Omit vs Pick

UtilityActionUse when
Pick<T, K>Keep only specified keysYou need a few fields from a large type
Omit<T, K>Remove specified keysYou need most fields but want to exclude a few
typescript
// These produce the same result: type A = Pick<User, "id" | "name" | "email">; type B = Omit<User, "password" | "createdAt">; // Both: { id: string; name: string; email: string }

Practical Use Cases

API DTOs (Data Transfer Objects)

typescript
interface Product { id: string; name: string; price: number; description: string; createdAt: Date; updatedAt: Date; } // For creating — no id or timestamps type CreateProductDTO = Omit<Product, "id" | "createdAt" | "updatedAt">; // For updating — no id, all fields optional type UpdateProductDTO = Partial<Omit<Product, "id">>;

Component Props

typescript
interface InputProps { value: string; onChange: (value: string) => void; label: string; error?: string; disabled?: boolean; type: string; } // Custom input doesn't need type (always "text") type TextInputProps = Omit<InputProps, "type">; // Password input manages its own type type PasswordInputProps = Omit<InputProps, "type"> & { showToggle?: boolean; };

Extending Types Safely

typescript
interface BaseEntity { id: string; createdAt: Date; updatedAt: Date; } // Override specific fields type CreateInput<T extends BaseEntity> = Omit<T, keyof BaseEntity> & { id?: string; // Make id optional for creation };

How Omit Works Internally

typescript
// Omit is built from Pick and Exclude: type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>; // Step by step: // 1. keyof User = "id" | "name" | "email" | "password" | "createdAt" // 2. Exclude<keyof User, "password"> = "id" | "name" | "email" | "createdAt" // 3. Pick<User, "id" | "name" | "email" | "createdAt"> = the final type

Important:

Omit is one of the most commonly used utility types. It's perfect for creating DTOs, removing sensitive fields from API responses, and building component prop types. Combine it with Partial, Required, and Pick for powerful type transformations.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

Finished reading?
Practice Problems