mergeWith es-toolkit
Deeply merges the source object into the target object using a custom merge function, modifying the target object.
Usage
mergeWith(target, source, merge)
Use mergeWith when you want to apply custom merge logic for each property when merging two objects. If the merge function returns undefined, the default deep merge logic is used.
Parameters
targetT extends Record<PropertyKey, any>required
The target object to merge the source object into. This object is modified.
sourceS extends Record<PropertyKey, any>required
The source object to merge into the target object.
merge(targetValue: any, sourceValue: any, key: string, target: T, source: S) => anyrequired
A custom merge function.
targetValue: The current value in the target objectsourceValue: The value in the source objectkey: The key of the property being mergedtarget: The target objectsource: The source object
Returns
Returns the target object with the source object merged in.
Examples
Try It
::: sandpack
:::
Source: es-toolkit
Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.