Skip to content

defaultsDeep

defaultsDeep(params): DefaultsDeepResult

Defined in: objects/defaults-deep/index.ts:37

Recursively assigns default values from source to target. For each property, if the target’s value is undefined (or the key is missing), the source’s value is used. When both target and source have plain objects at the same key, they are merged recursively. Existing null, 0, "", false, and array values in the target are preserved.

DefaultsDeepParams

The parameters object

DefaultsDeepResult

A new object (inputs are not mutated)

defaultsDeep({
target: { db: { port: 5432 } },
source: { db: { port: 3306, host: "localhost" }, debug: false },
});
// => { db: { port: 5432, host: "localhost" }, debug: false }

deep defaults, nested defaults, fill undefined recursive, fallback object deep

lodash/defaultsDeep — semantic reference (https://lodash.com/docs/#defaultsDeep)

Error if target is not a plain object

Error if source is not a plain object