The type of the input record
The readonly array type of keys to pick from the record
A new record containing only the specified keys and their values
const user = {
id: 1,
name: 'Bob',
email: 'bob@example.com',
password: 'secret',
role: 'admin',
};
// Direct usage
const publicInfo = Obj.pick(user, ['id', 'name', 'role']);
assert.deepStrictEqual(publicInfo, {
id: 1,
name: 'Bob',
role: 'admin',
});
// Curried usage with pipe
const nameAndEmail = pipe(user).map(Obj.pick(['name', 'email'])).value;
assert.deepStrictEqual(nameAndEmail, {
name: 'Bob',
email: 'bob@example.com',
});
Creates a new record that contains only the specified keys from the source record. This function supports both direct usage and curried form for functional composition.
Type Safety: Only keys that exist in the source record type are allowed, preventing runtime errors from accessing non-existent properties.
The readonly array type of keys to pick from the record
A readonly array of keys to include in the result
A new record containing only the specified keys and their values
const user = {
id: 1,
name: 'Bob',
email: 'bob@example.com',
password: 'secret',
role: 'admin',
};
// Direct usage
const publicInfo = Obj.pick(user, ['id', 'name', 'role']);
assert.deepStrictEqual(publicInfo, {
id: 1,
name: 'Bob',
role: 'admin',
});
// Curried usage with pipe
const nameAndEmail = pipe(user).map(Obj.pick(['name', 'email'])).value;
assert.deepStrictEqual(nameAndEmail, {
name: 'Bob',
email: 'bob@example.com',
});
Creates a new record that contains only the specified keys from the source record. This function supports both direct usage and curried form for functional composition.
Type Safety: Only keys that exist in the source record type are allowed, preventing runtime errors from accessing non-existent properties.