Function: extendDeep()
ts
function extendDeep(parent, child?): ObjectType<any>;Recursively extends an object by deeply copying properties from parent to child. 通过将属性从父对象深度复制到子对象来递归扩展对象。
Parameters
| Parameter | Type | Description |
|---|---|---|
parent | ObjectType<any> | The parent object to copy from / 要复制的父对象 |
child | ObjectType<any> | The child object to merge into / 要合并到的子对象 |
Returns
ObjectType<any>
The extended child object / 扩展后的子对象
Example
typescript
const parent = { a: { b: 1, c: 2 }, d: [1, 2, 3], e: 'hello' }
const child = { a: { c: 3, f: 4 } }
extendDeep(parent, child)
// => { a: { b: 1, c: 2, f: 4 }, d: [1, 2, 3], e: 'hello' }
// Arrays are replaced, not merged
extendDeep({ arr: [1, 2] }, {}) // => { arr: [] }
// Nested objects are deeply copied
extendDeep({ user: { name: 'John', settings: { theme: 'dark' } } }, {})
// => { user: { name: 'John', settings: { theme: 'dark' } } }Since
1.0.0