export function deepMerge(target: any, source: any): any { if ( typeof target !== "object" || target === null || typeof source !== "object" || source === null ) { return source; } const result = Array.isArray(target) ? [...target] : { ...target }; for (const key of Object.keys(source)) { const targetValue = result[key]; const sourceValue = source[key]; if (Array.isArray(targetValue) && Array.isArray(sourceValue)) { result[key] = [...targetValue, ...sourceValue]; } else if ( targetValue && typeof targetValue === "object" && sourceValue && typeof sourceValue === "object" ) { result[key] = deepMerge(targetValue, sourceValue); } else { result[key] = sourceValue; } } return result; }