Typescript Foundations / Utility Types

Pick

🎯 Pick<T, K>

Pick<T, K> creates a new type by selecting specific properties from an existing type.

It is useful when you only need a few properties from a larger type.

🔹 Example

type User = {
  name: string;
  age: number;
  email: string;
  password: string;
};

type UserPreview = Pick<User, "name" | "email">;

const user: UserPreview = {
  name: "Bhaskar",
  email: "bhaskar@example.com"
};

Here, UserPreview contains only:

{
  name: string;
  email: string;
}

The age and password properties are not included.

💡 Common Use

Pick is useful when creating smaller versions of existing types, such as user previews, API responses, or form data.

Remember: Pick<T, K> → Selects specific properties from T.