Skip to content

props() function

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

Signature:

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

Example

ts
// 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

Released under the Apache-2.0 License.