TypeScript 7 reference · Utility Types

TypeScript Pick<Type, Keys> Utility Type

Build a type from just some properties of another type. Handy for API responses and props that need a subset.

TypeScript 7 Since 2.1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Pick<Type, Keys>

Parameters

ParameterDescription
Type The object type to transform.
Keys A union of property names, e.g. "id" | "name".

Return value

A type with only the picked properties.

Examples

A public subset of a userTry it yourself
interface User {
  id: number;
  name: string;
  email: string;
  passwordHash: string;
}
type PublicUser = Pick<User, "id" | "name">;
const u: PublicUser = { id: 1, name: "Ana" };
console.log(u);

Output

{ id: 1, name: 'Ana' }
Accept only what you useTry it yourself
interface Todo {
  title: string;
  done: boolean;
  due: string;
}
function preview(t: Pick<Todo, "title" | "done">) {
  return `${t.done ? "[x]" : "[ ]"} ${t.title}`;
}
console.log(preview({ title: "Buy milk", done: false }));

Output

[ ] Buy milk

Version history

VersionChange
TypeScript 2.1Added

Was this page helpful?