SyntaxStudy
Sign Up
Home TypeScript Reference Pick<T, K> / Omit<T, K>

Pick<T, K> / Omit<T, K>

class

Pick selects a subset of properties; Omit excludes specified properties. Both create new types.

Syntax

Pick<Type, "key1" | "key2"> Omit<Type, "key">

Example

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

// Only id, name, email
type PublicUser = Pick<User, 'id' | 'name' | 'email'>;

// Everything except password
type SafeUser = Omit<User, 'password'>;

// Common pattern: DTO without auto-generated fields
type CreateUserDTO = Omit<User, 'id' | 'createdAt'>;