@jiminp/tooltool
    Preparing search index...

    Function recursiveMerge

    • Recursively merges a patch object into a base object.

      This function performs a deep merge for nested records. Arrays and primitive types in the patch object will overwrite the corresponding values in base.

      Type Parameters

      • T extends Record<string, unknown>

        The type of the base record.

      Parameters

      • base: T

        The initial record object.

      • patch: RecursivePartial<T> | null | undefined

        The partial record containing updates. If null or undefined, base is returned as-is.

      Returns T

      A new object containing the merged properties.

      const base = { a: 1, b: { c: 2 } };
      const patch = { b: { d: 3 }, e: 4 };
      const result = recursiveMerge(base, patch);
      // { a: 1, b: { c: 2, d: 3 }, e: 4 }
      • This function is pure; it does not modify base or patch.
      • In some cases, the original base will be returned, so take care when modifying the result.
      • Properties with undefined values in patch are ignored.
      • Properties with null values in patch overwrite the values in base.