R
fn

pick

v0.0.3tested

Returns a partial copy of an object containing only the keys specified

Examples

ts
pick({ a: 1, b: 2, c: 3 }, 'a') // => { a: 1 }
ts
pick({ a: 1, b: 2, c: 3 }, ['a', 'b']) // => { a: 1, b: 2 }

Signature

ts
export function pick<Target extends object, Key extends keyof Target>(
  target: Target,
  keys: Arrayable<Key>,
): Pick<Target, Key>{ ... }

Type Parameters

Targetextends object
Keyextends keyof Target

Parameters

ParameterTypeDescription
targetTargetThe object to pick keys from
keysArrayable<Key>The object to pick keys from

Returns

Pick<Target, Key>The new object with the specified keys picked