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.
Examples
Section titled “Examples”const merged = { ...(options || {}) };const config = { ...(settings ?? {}) };const result = { ...(getValue() || {}) };const data = { ...(nested.property ?? {}) };const merged = { ...options };const config = { ...settings };const result = { ...getValue() };const data = { ...nested.property };const merged = { ...(options || { defaultValue: true }) };Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.