mergeDeep

Commons
stable

Recursively merge two plain objects into a new object. Nested objects are merged deeply; arrays are combined via an optional resolver, otherwise the target wins.

API

Signature

Full TypeScript signature sourced from the util file.

typescript

API

Parameters

Input parameters accepted by this util.

source
Record<string, unknown>
{}
The base object. Its keys are copied first and act as defaults.
target
Record<string, unknown>
{}
The overriding object. Its values win over the source unless both sides are mergeable objects.
arrayFn
(a: Array<unknown>, b: Array<unknown>) => Array<unknown>
Optional resolver invoked when both properties are arrays. When omitted, the target array replaces the source array.

API

Return value

The value returned by this util.

A new object combining source and target. Neither input is mutated.

Usage

Examples

Ready-to-paste usage snippets.

Deep merge with nested objects

typescript