mirror of
https://github.com/theoludwig/theoludwig.git
synced 2026-08-25 09:21:33 +02:00
17 lines
511 B
TypeScript
17 lines
511 B
TypeScript
export const deepMerge = <Object1 extends object, Object2 extends object = Object1>(
|
|
object1: Object1,
|
|
object2: Object2,
|
|
): Object1 & Object2 => {
|
|
const result = { ...object1 } as Object1 & Object2
|
|
for (const key in object2) {
|
|
if (Object.hasOwn(object2, key)) {
|
|
if (typeof object2[key] === "object" && object2[key] !== null) {
|
|
result[key] = deepMerge(result[key] as any, object2[key] as any)
|
|
} else {
|
|
result[key] = object2[key] as any
|
|
}
|
|
}
|
|
}
|
|
return result
|
|
}
|