What it Does

Creates a new type by excluding specific properties from an existing type.

Syntax

type OmittedType = Omit<OriginalType, 'key1' | 'key2'>;

Use Cases

Detailed Example

interface User {
  id: number;
  name: string;
  email: string;
  password: string;
  createdAt: Date;
  updatedAt: Date;
}

*// For creating new users - no id or timestamps*
type CreateUserRequest = Omit<User, 'id' | 'createdAt' | 'updatedAt'>;

*// For public display - no password*
type PublicUser = Omit<User, 'password'>;

const newUser: CreateUserRequest = {
  name: "Alice",
  email: "alice@example.com",
  password: "secret123"
  *// id, createdAt, updatedAt not allowed*
};