Skip to main content

props

props() function

Returns an array containing the values of the specified props in the given object.

Signature:
declare function props<K extends readonly Key[], T>(key: K, obj: T): PropsReturnType<K, T>;

declare function props<K extends readonly Key[]>(key: K): <T>(obj: T) => PropsReturnType<K, T>;

Example

// get the `name` and `age` properties from an object
const person = { name: "John", age: 30, address: "123 Main St" };
const [name, age, phone] = props(["name", "age", "phone"], person); // ["John", 30, undefined]

// with pipe
pipe(
person,
props(["name", "age", "phone"]),
);

// get the `address` and `phone` properties from an object that may be null or undefined
const maybePerson = null;
const [address, phone] = props(["address", "phone"], maybePerson); // [undefined, undefined]

Open Source Code