What it Does

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

Syntax

type PickedType = Pick<OriginalType, 'key1' | 'key2'>;

Use Cases

Detailed Example

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

*// Profile display only needs these fields*
type UserProfile = Pick<User, 'id' | 'name' | 'email'>;

*// Login credentials*
type LoginCredentials = Pick<User, 'email' | 'password'>;

const profile: UserProfile = {
  id: 1,
  name: "John",
  email: "john@example.com"
  *// password not needed or allowed*
};

When to Use

When to Avoid