app/@overflow/core/merge.ts

11 lines
300 B
TypeScript
Raw Normal View History

2018-08-17 06:11:55 +00:00
/** Create a copy of an object by merging it with a subset of its properties. */
export function merge<T, K extends keyof T>(obj: T, subset: Pick<T, K>): T {
const copy = Object.assign({}, obj);
for (const k in subset) {
if (subset[k]) {
copy[k] = subset[k];
}
}
return copy;
}