js-hub / utils /pick.ts
coyotte508's picture
coyotte508 HF Staff
Add 1 files
21dd449 verified
/**
* Return copy of object, only keeping whitelisted properties.
*/
export function pick<T, K extends keyof T>(o: T, props: K[] | ReadonlyArray<K>): Pick<T, K> {
return Object.assign(
{},
...props.map((prop) => {
if (o[prop] !== undefined) {
return { [prop]: o[prop] };
}
})
);
}