Skip to content

objectSpreadUnnecessaryFallbacks

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

✅ This rule is included in the ts logical 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 merged = { ...(options || {}) };
const config = { ...(settings ?? {}) };
const result = { ...(getValue() || {}) };
const data = { ...(nested.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 ❤️‍🔥 in Boston by Josh Goldberg and contributors.