pick function

Pick specific properties from an object.

Example

const user = { id: "1", name: "John", email: "john@example.com", password: "secret" };
const safe = pick(user, "id", "name", "email"); // password excluded

Signature

pick<T, K extends string | number | symbol>(obj: T, ...keys: K[]): Pick<T, K>

Type Parameters

T

Object type

K

Keys to pick

Parameters

obj

Source object

keys

Property names to include

Returns

New object with only the picked properties