10 lines
267 B
TypeScript
10 lines
267 B
TypeScript
|
export default function take<T>(object: T, keys: string[]): Partial<T> {
|
||
|
if (!object) return null;
|
||
|
return Object.keys(object).reduce<Partial<T>>((obj, field) => {
|
||
|
if (keys.includes(field)) {
|
||
|
obj[field] = object[field];
|
||
|
}
|
||
|
return obj;
|
||
|
}, {});
|
||
|
}
|