/** * Populates an object with properties of another object * @param {Object} source Source object * @param {string[]} properties Properties names to include * @returns object populated with the picked keys */ export const pick = >( source: T, keys: (keyof T)[] = [], ) => { return keys.reduce((o, key) => { if (key in source) { o[key] = source[key]; } return o; }, {} as Partial); }; export const pickBy = >( source: T, predicate: (value: T[K], key: K, collection: T) => boolean, ) => { return (Object.keys(source) as (keyof T)[]).reduce((o, key) => { if (predicate(source[key], key, source)) { o[key] = source[key]; } return o; }, {} as Partial); };