@jiminp/tooltool
    Preparing search index...

    Function recursiveMerge

    • Recursively merges a patch into a base record without mutating either input.

      Deep-merges only pairs of plain records. Arrays, functions, other objects, and primitives replace their base values by reference rather than being traversed.

      Type Parameters

      • Base extends Record<string, unknown>

        The base record type.

      • Patch extends Nullable<object> = Nullable<RecursivePartial<Base>>

        The inferred patch type, including additions and replacements.

      Parameters

      • base: Base

        The base record.

      • patch: Patch

        Record updates, or null or undefined to leave base unchanged.

      Returns RecursiveMergeResult<Base, Patch>

      The merged record, the replacement patch, or base for a nullish or identical patch.

      • A plain record has exactly this realm's Object.prototype or null as its prototype. Class instances and records with another realm's object prototype are replacements.
      • Patch properties may add keys or replace existing values with different types.
      • Plain-record merges apply own enumerable string-keyed patch properties and ignore inherited properties. Names such as __proto__ become own data properties, not prototype operations. An undefined field is ignored; a null field overwrites.
      • Non-identical pairs of plain records create new ordinary records. Recursively merged branches are copied; untouched branches and replacement values retain input references. This is not a deep clone.
      const base = { a: 1, b: { c: 2 } };
      const patch = { b: { d: 3 }, e: 4 };
      recursiveMerge(base, patch); // { a: 1, b: { c: 2, d: 3 }, e: 4 }