Function: defaults()
ts
function defaults<T, D>(object, source): T & D;Fills undefined properties in an object with default values. 仅为对象中值为 undefined 的属性填充默认值。
Type Parameters
| Type Parameter | Description |
|---|---|
T extends Record<PropertyKey, unknown> | The target object type / 目标对象类型 |
D extends Record<PropertyKey, unknown> | The defaults object type / 默认值对象类型 |
Parameters
| Parameter | Type | Description |
|---|---|---|
object | T | The target object / 目标对象 |
source | D | The defaults source / 默认值来源 |
Returns
T & D
A new object with defaults applied / 应用默认值后的新对象
Example
ts
defaults({ a: 1 }, { a: 9, b: 2 })
// => { a: 1, b: 2 }Since
1.2.0