app/@overflow/core/merge.ts
crusader 7c915f6d5f ing
2018-08-17 15:11:55 +09:00

11 lines
300 B
TypeScript

/** 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;
}