diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index f7e0466dc..354843a55 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -502,6 +502,45 @@ var optionsPartialRight = { defaultsDeep(optionsPartialRight, _.templateSettings); + + + + + +/********** +* Objects * +***********/ +var mergeNames = { + 'stooges': [ + { 'name': 'moe' }, + { 'name': 'larry' } + ] +}; + +var mergeAges = { + 'stooges': [ + { 'age': 40 }, + { 'age': 50 } + ] +}; + +_.merge(mergeNames, mergeAges); +// → { 'stooges': [{ 'name': 'moe', 'age': 40 }, { 'name': 'larry', 'age': 50 }] } + +var mergeFood = { + 'fruits': ['apple'], + 'vegetables': ['beet'] +}; + +var mergeOtherFood = { + 'fruits': ['banana'], + 'vegetables': ['carrot'] +}; + +_.merge(mergeFood, mergeOtherFood, function(a, b) { + return _.isArray(a) ? a.concat(b) : undefined; +}); + //////////////////////////////////////////////////////////////////////////////////////// //WHAT'S LEFT //////////////////////////////////////////////////////////////////////////////////////// diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index cf6c0ecc2..f939688de 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1905,7 +1905,119 @@ declare module _ { - + /********** + * Objects * + ***********/ + + /** + * Recursively merges own enumerable properties of the source object(s), that don't resolve + * to undefined into the destination object. Subsequent sources will overwrite property + * assignments of previous sources. If a callback is provided it will be executed to produce + * the merged values of the destination and source properties. If the callback returns undefined + * merging will be handled by the method instead. The callback is bound to thisArg and invoked + * with two arguments; (objectValue, sourceValue). + * @param object The destination object. + * @param s1-8 The source object(s) + * @param callback The function to customize merging properties. + * @param thisArg The this binding of callback. + * @return The destination object. + **/ + export function merge( + object: any, + s1: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any; + + /** + * @see _.merge + **/ + export function merge( + object: any, + s1: any, + s2: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any; + + /** + * @see _.merge + **/ + export function merge( + object: any, + s1: any, + s2: any, + s3: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any; + + /** + * @see _.merge + **/ + export function merge( + object: any, + s1: any, + s2: any, + s3: any, + s4: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any; + + /** + * @see _.merge + **/ + export function merge( + object: any, + s1: any, + s2: any, + s3: any, + s4: any, + s5: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any; + + /** + * @see _.merge + **/ + export function merge( + object: any, + s1: any, + s2: any, + s3: any, + s4: any, + s5: any, + s6: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any; + + /** + * @see _.merge + **/ + export function merge( + object: any, + s1: any, + s2: any, + s3: any, + s4: any, + s5: any, + s6: any, + s7: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any; + + /** + * @see _.merge + **/ + export function merge( + object: any, + s1: any, + s2: any, + s3: any, + s4: any, + s5: any, + s6: any, + s7: any, + s8: any, + callback?: (objectValue: any, sourceValue: any) => any, + thisArg?: any): any;