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.

AEconsB0mergAE = <{ sp ansty="le--0:#7FDBCA;--1:#096E">72.<..sp ansty="le--0:#D6DEEB;--1:#403F">53(optioAE || <{}sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><};d>AEconsB0confAE = <{ sp ansty="le--0:#7FDBCA;--1:#096E">72.<..sp ansty="le--0:#D6DEEB;--1:#403F">53(settinAE ?? <{}sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><};d>AEconsB0resuAE = <{ sp ansty="le--0:#7FDBCA;--1:#096E">72.<..sp ansty="le--0:#D6DEEB;--1:#403F">5<3(sp ansty="le--0:#82AAFF;--1:#3B61">B0getVal53<()sp ansty="le--0:#C792EA;--1:#8844">AE || <{}sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><};d>AEconsB0daAE = <{ sp ansty="le--0:#7FDBCA;--1:#096E">72.<..sp ansty="le--0:#D6DEEB;--1:#403F">53(nestA72properAE ?? <{}sp ansty="le--0:#D6DEEB;--1:#403F">5<3)sp ansty="le--0:#C792EA;--1:#8844">AE< }sp ansty="le--0:#D6DEEB;--1:#403F">5<3;d ivclassNa="meco"><};d>
44AEco61B0me44AE <= { spans="tyle--0:#7FDBCA;--1:#09">6E7<2... spans="tyle--0:#D6DEEB;--1:#40">3F53opt443<;di vdivclass="Nameexpressive-">44AEco61B0co44AE <= { spans="tyle--0:#7FDBCA;--1:#09">6E7<2... spans="tyle--0:#D6DEEB;--1:#40">3F53sett443<;di vdivclass="Nameexpressive-">44AEco61B0re44AE <= { spans="tyle--0:#7FDBCA;--1:#09">6E7<2... spans="tyle--0:#82AAFF;--1:#3B">61B0getV3F<53() spans="tyle--0:#C792EA;--1:#88">443<) }><;di vdivclass="Nameexpressive-">44AEco61B044AE <= { spans="tyle--0:#7FDBCA;--1:#09">6E7<2... spans="tyle--0:#D6DEEB;--1:#40">3F53ne4<4AE. spans="tyle--0:#7FDBCA;--1:#09">6E72prop443<;di vdivclass="Nameexpressive-">44AEco61B0me44AE <= { spans="tyle--0:#7FDBCA;--1:#09">6E7<2... spans="tyle--0:#D6DEEB;--1:#40">3F53(opt44AE || { defaultVal4848443443<) }>

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.