source: node_modules/es-toolkit/dist/object/merge.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * Merges the properties of the source object into the target object.
3 *
4 * This function performs a deep merge, meaning nested objects and arrays are merged recursively.
5 * If a property in the source object is an array or an object and the corresponding property in the target object is also an array or object, they will be merged.
6 * If a property in the source object is undefined, it will not overwrite a defined property in the target object.
7 *
8 * Note that this function mutates the target object.
9 *
10 * @param {T} target - The target object into which the source object properties will be merged. This object is modified in place.
11 * @param {S} source - The source object whose properties will be merged into the target object.
12 * @returns {T & S} The updated target object with properties from the source object merged in.
13 *
14 * @template T - Type of the target object.
15 * @template S - Type of the source object.
16 *
17 * @example
18 * const target = { a: 1, b: { x: 1, y: 2 } };
19 * const source = { b: { y: 3, z: 4 }, c: 5 };
20 *
21 * const result = merge(target, source);
22 * console.log(result);
23 * // Output: { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
24 *
25 * @example
26 * const target = { a: [1, 2], b: { x: 1 } };
27 * const source = { a: [3], b: { y: 2 } };
28 *
29 * const result = merge(target, source);
30 * console.log(result);
31 * // Output: { a: [3, 2], b: { x: 1, y: 2 } }
32 *
33 * @example
34 * const target = { a: null };
35 * const source = { a: [1, 2, 3] };
36 *
37 * const result = merge(target, source);
38 * console.log(result);
39 * // Output: { a: [1, 2, 3] }
40 */
41declare function merge<T extends Record<PropertyKey, any>, S extends Record<PropertyKey, any>>(target: T, source: S): T & S;
42
43export { merge };
Note: See TracBrowser for help on using the repository browser.