Skip to content

Typings — Object

Source: DeepMerge.ts

Import

ts
import type { IMergeArray, IMergeObject, IDeepMergeOptions } from '@litert/utils-object';

IMergeArray<T1, T2>

Computes the recursive merge result type for two array types. When both arrays contain objects, their element types are recursively merged via IMergeObject; otherwise the second array's element type wins.

ts
type IMergeArray<T1 extends any[], T2 extends any[]> = T1[0] extends IObject
    ? T2[0] extends IObject
        ? Array<IMergeObject<T1[0], T2[0]>>
        : T2
    : T2;

IMergeObject<T1, T2>

Computes the recursive merge result type for two object types. For each key:

  • If the key exists only in T2, the T2 value type is used.
  • If the key exists only in T1, the T1 value type is used.
  • If the key exists in both and both are objects, the types are recursively merged.
  • If both are arrays, IMergeArray is applied.
  • Otherwise, the T2 value type wins.
ts
type IMergeObject<T1 extends IObject, T2 extends IObject> = { ... };

IDeepMergeOptions

Options accepted by the deepMerge function.

ts
interface IDeepMergeOptions {
    arrayAsValue?: boolean;
    nullAsEmptyObject?: boolean;
}

Properties

  • arrayAsValue?: boolean (default: false)

    When true, arrays are treated as plain values (the second array fully replaces the first instead of being merged element-by-element).

  • nullAsEmptyObject?: boolean (default: false)

    When true, a null value in either object is treated as an empty object {} during the merge, preventing a null from overwriting an existing object value.