mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
[deepmerge] Allow partial types in deepmerge
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.
This commit is contained in:
@@ -16,4 +16,14 @@ const expected = {
|
||||
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
|
||||
});
|
||||
|
||||
10
types/deepmerge/index.d.ts
vendored
10
types/deepmerge/index.d.ts
vendored
@@ -1,17 +1,19 @@
|
||||
// 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
|
||||
|
||||
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