@@ -8,6 +8,39 @@ export type DeepPartial<T> = T extends Function
88 ? { [ K in keyof T ] ?: DeepPartial < T [ K ] > }
99 : T ;
1010
11+ /**
12+ * Recursively merges a patch object into a target object.
13+ *
14+ * Behavior:
15+ * - Primitive values, nulls, and functions from patch replace target values
16+ * - Arrays from patch replace target arrays entirely
17+ * - Plain objects are recursively merged
18+ * - Undefined values in patch are skipped (target values are preserved)
19+ *
20+ * @template T - The type of the target object
21+ * @param target - The base object to merge into
22+ * @param patch - The partial object with values to merge; undefined/null values are ignored
23+ * @returns A new merged object of type T
24+ *
25+ * @example
26+ * const base = {
27+ * name: "John",
28+ * tags: ["a", "b"],
29+ * address: { city: "NYC", zip: "10001" }
30+ * };
31+ * const patch = {
32+ * tags: ["x", "y", "z"], // array replaced entirely
33+ * address: { city: "LA" }, // merged (zip kept from base)
34+ * email: "[email protected] " // new property added 35+ * };
36+ * const result = deepMerge(base, patch);
37+ * // Result: {
38+ * // name: "John",
39+ * // tags: ["x", "y", "z"],
40+ * // address: { city: "LA", zip: "10001" },
41+ 42+ * // }
43+ */
1144export function deepMerge < T > ( target : T , patch : DeepPartial < T > ) : T {
1245 if ( patch === undefined || patch === null ) return target ;
1346
@@ -38,5 +71,3 @@ export function deepMerge<T>(target: T, patch: DeepPartial<T>): T {
3871
3972 return out as T ;
4073}
41-
42- export const asDeepPartial = < T > ( v : DeepPartial < T > ) => v ;
0 commit comments