Reference / TypeScript
Pick<Type, Keys>
Constructs a type by picking the set of properties Keys (string literal or union of string literals) from Type.
Syntax
type Pick<T, K extends keyof T> = { [P in K]: T[P]; }Parameters
| Name | Type | Description |
|---|---|---|
| Type | object | The source object type. |
| Keys | keyof Type | Union of keys to extract. |
Examples
Extracting public profile
interface User { id: number; name: string; passwordHash: string; email: string; }
type PublicUser = Pick<User, 'id' | 'name'>;
// { id: number; name: string }The opposite of Omit<Type, Keys>.