deepMerge()function

deepMerge(left: L, right: R): L & R
deepMerge(left: ImmutableArray<L>, right: ImmutableArray<R>): ImmutableArray<L | R>
deepMerge(left: unknown, right: R): R
ParamType
leftL
The left value to merge into. required
rightR
The right value to merge in. required
leftImmutableArray<L>
Immutable array: an array that cannot be changed. required
rightImmutableArray<R>
Immutable array: an array that cannot be changed. required
leftunknown
required
rightR
required
Return
L & R
Merged value.
- Will be left instance if no properties/items changed.
- Will be a new merged instance otherwise.
ImmutableArray<L | R>
Immutable array: an array that cannot be changed.
R

Deeply merge two unknown values.

  • Two objects: props are merged together (deeply).
  • Two arrays: unique items are merged together (shallowly — arrays have no way to deep merge because array keys are not stable).
  • Any other value: right value is returned.

Examples

deepMerge({ a: { b: 1 } }, { a: { c: 2 } }) // { a: { b: 1, c: 2 } }