11 lines
300 B
TypeScript
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;
|
|
}
|