Skip to content

objectSpreadUnnecessaryFallbacks

Reports empty object fallbacks in object spread expressions that have no effect.

✅ This rule is included in the ts logical and logicalStrict presets.

When spreading a value into an object literal, JavaScript handles undefined and null by skipping them without throwing an error. This means that fallback patterns like { ...value || {} } or { ...value ?? {} } are unnecessary.

This rule reports when an object spread fallback is an empty object.

const
const merged: any
merged
= { ...(
const options: any
options
|| {}) };
const
const config: any
config
= { ...(
const settings: any
settings
?? {}) };
const
const result: any
result
= { ...(
const getValue: any
getValue
() || {}) };
const
const data: any
data
= { ...(
const nested: any
nested
.
any
property
?? {}) };

This rule is not configurable.

If you prefer the explicit fallback pattern for clarity, even when it’s not strictly necessary, you might want to disable this rule. Some developers find { ...value || {} } more readable as it explicitly signals the intent to handle potentially nullish values, even though the behavior is identical without the fallback.

Made with ❤️‍🔥 around the world by the Flint team and contributors.