Web Analytics

Pick & Omit

Intermediate~18 min

Pick and Omit utility types create new types by selecting or excluding specific properties from existing types.

Pick & Omit Types

Output
Click Run to execute your code
Utility Types:
  • Pick<T, K> - Select specific properties
  • Omit<T, K> - Exclude specific properties

Pick vs Omit

Utility Action Use When
Pick Include only specified Few properties needed
Omit Exclude specified Most properties needed

Common Mistakes

1. Wrong Property Names

interface User {
    id: number;
    userName: string;
}

// โœ— Error - 'name' doesn't exist
type UserPreview = Pick;

// โœ“ Correct
type UserPreview = Pick;
Best Practice: Use Pick when you need few properties, Omit when excluding few.

Summary

  • Pick<T, K> selects specific properties
  • Omit<T, K> excludes specific properties
  • Perfect for creating focused types
  • Type-safe property selection