Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
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

NameTypeDescription
TypeobjectThe source object type.
Keyskeyof TypeUnion 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>.