mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 23:37:04 +00:00
Merge pull request #19444 from syy1125/master
[deepmerge] Allow partial types in deepmerge
This commit is contained in:
@@ -1,19 +1,29 @@
|
||||
import * as deepmerge from "deepmerge";
|
||||
|
||||
const x = {
|
||||
foo: { bar: 3 },
|
||||
array: [{ does: 'work', too: [1, 2, 3] }]
|
||||
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' }]
|
||||
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
|
||||
foo: { bar: 3, baz: 4 },
|
||||
array: [{ does: 'work', too: [1, 2, 3, 4, 5, 6] }, { really: 'yes' }],
|
||||
quux: 5
|
||||
};
|
||||
|
||||
const result = deepmerge<any>(x, y);
|
||||
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
|
||||
});
|
||||
|
||||
Vendored
+7
-4
@@ -1,17 +1,20 @@
|
||||
// Type definitions for deepmerge 1.3
|
||||
// Project: https://github.com/KyleAMathews/deepmerge
|
||||
// Definitions by: marvinscharle <https://github.com/marvinscharle>
|
||||
// syy1125 <https://github.com/syy1125>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.1
|
||||
|
||||
export = deepmerge;
|
||||
|
||||
declare function deepmerge<T>(x: T, y: T, options?: deepmerge.Options<T>): T;
|
||||
declare function deepmerge<T>(x: Partial<T>, y: Partial<T>, options?: deepmerge.Options): T;
|
||||
declare function deepmerge<T1, T2>(x: T1, y: T2, options?: deepmerge.Options): T1 & T2;
|
||||
|
||||
declare namespace deepmerge {
|
||||
interface Options<T> {
|
||||
interface Options {
|
||||
clone?: boolean;
|
||||
arrayMerge?(destination: T, source: T, options?: Options<T>): T;
|
||||
arrayMerge?(destination: any[], source: any[], options?: Options): any[];
|
||||
}
|
||||
|
||||
function all<T>(objects: T[], options?: Options<T>): T;
|
||||
function all<T>(objects: Array<Partial<T>>, options?: Options): T;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user