export type DeepPartial = { [K in keyof T]?: T[K] extends Array ? Array> : T[K] extends object ? DeepPartial : T[K]; }; export function isPlainObject(value: unknown): value is Record { return Object.prototype.toString.call(value) === '[object Object]'; } export function deepMerge(base: T, override: DeepPartial): T { if (!isPlainObject(base) || !isPlainObject(override)) return (override as T) ?? base; const result: Record = { ...(base as Record) }; for (const [key, value] of Object.entries(override)) { if (value === undefined) continue; const existing = result[key]; if (Array.isArray(value)) { result[key] = value; continue; } if (isPlainObject(existing) && isPlainObject(value)) { result[key] = deepMerge(existing, value); continue; } result[key] = value; } return result as T; }