mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-24 05:06:02 +08:00
Sometimes deepmerge is used for overwriting only a few properties in a larger object. Allowing partial types lets users deepmerge without having to typecast in those cases. In addition, also updated the typings for arrayMerge to indicate that it will be operating on two arrays.
30 lines
628 B
TypeScript
30 lines
628 B
TypeScript
import * as deepmerge from "deepmerge";
|
|
|
|
const x = {
|
|
foo: { bar: 3 },
|
|
array: [{ does: 'work', too: [1, 2, 3] }]
|
|
};
|
|
const y = {
|
|
foo: { baz: 4 },
|
|
quux: 5,
|
|
array: [{ does: 'work', too: [4, 5, 6] }, { really: 'yes' }]
|
|
};
|
|
|
|
const expected = {
|
|
foo: { bar: 3, baz: 4 },
|
|
array: [{ does: 'work', too: [1, 2, 3, 4, 5, 6] }, { really: 'yes' }],
|
|
quux: 5
|
|
};
|
|
|
|
const result = deepmerge(x, y);
|
|
const anyResult = deepmerge<any>(x, y);
|
|
|
|
function reverseConcat(dest: number[], src: number[]) {
|
|
return src.concat(dest);
|
|
}
|
|
|
|
const withOptions = deepmerge(x, y, {
|
|
clone: false,
|
|
arrayMerge: reverseConcat
|
|
});
|