Utility Types - Pick
In this page:
Basic Pick
Pick<T, K> selects one or more properties from an existing type T, given a union of property-name literals K, and produces a smaller type containing just those properties.
Example: Basic Pick
interface User {
id: number;
name: string;
email: string;
}
type UserPreview = Pick<User, "id" | "name">;
const preview: UserPreview = { id: 1, name: "Ravi" };
console.log(preview);
Pick for Function Arguments
Pick can define a smaller parameter object for functions that only need a few fields from a larger model, instead of requiring the entire original type to be passed in.
Example: Pick for Function Arguments
interface User {
id: number;
name: string;
email: string;
}
function greet(user: Pick<User, "name">) {
console.log("Hello", user.name);
}
greet({ name: "Ravi" });
Pick with Interfaces
Pick works with interfaces exactly as it does with type aliases, since both ultimately describe a set of named, typed properties that Pick can select from. This means you can freely mix Pick with either style of type definition without any special-casing.
Example: Pick with Interfaces
interface Product {
id: number;
title: string;
price: number;
}
type ProductSummary = Pick<Product, "title" | "price">;
const s: ProductSummary = { title: "Book", price: 20 };
console.log(s);
Pick and Type Safety
Pick requires the selected property names to actually exist on the source type, which gives strong compile-time checking against typos in the list of keys you're picking.
Example: Pick and Type Safety
interface User {
id: number;
name: string;
}
type IdOnly = Pick<User, "id">;
const u: IdOnly = { id: 5 };
console.log(u.id);
When to Use Pick
Use Pick when you want a smaller, focused view of an existing type based on only some of its properties, rather than duplicating a subset of fields into a brand-new type definition.
Example: When to Use Pick
interface Article {
id: number;
title: string;
body: string;
author: string;
}
type ArticleHeader = Pick<Article, "title" | "author">;
const header: ArticleHeader = { title: "News", author: "Ravi" };
console.log(header);
Chapter Quiz — Complete all 20 topics to unlock
0/20 topics done
Complete these topics first:
- TypeScript Advanced Types
- Mapped Types
- Conditional Types
- Custom Type Guards
- Assertion Functions
- Control Flow Analysis
- Exhaustiveness Checking
- Satisfies Operator
- Template Literal Types
- Utility Types - Partial
- Utility Types - Required
- Utility Types - Readonly
- Utility Types - Pick
- Utility Types - Omit
- Utility Types - Record
- Utility Types - Exclude and Extract
- Utility Types - NonNullable
- Utility Types - ReturnType
- Utility Types - Parameters
- TypeScript 5 Updates