Skip to content

defaults

defaults<R, P>(…args): R

Defined in: packages/core/src/object/defaults.ts:24

Assign default options to an object.

The first argument has the highest priority, the last argument the lowest. Only properties that are undefined in the target object will be assigned from the source objects.

This is equivalent to _.defaults from Lodash.

R extends object

P extends Partial<R> = Partial<R>

…[…(P | null | undefined)[], R]

The objects to merge.

R

The merged object.

const options = defaults({ a: 1 }, { a: 2, b: 2 }, { a: 3, b: 3, c: 3 });
console.log(options); // { a: 1, b: 2, c: 3 }
```;