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: {
[x: string]: unknown;
}
merged
= { ...(
const options: Record<string, unknown>
options
|| {}) };
const
const config: {
[x: string]: unknown;
}
config
= { ...(
const settings: Record<string, unknown>
settings
?? {}) };
const
const result: {
[x: string]: unknown;
}
result
= { ...(
const getValue: () => Record<string, unknown>
getValue
() || {}) };
const
const data: {
[x: string]: unknown;
}
data
= { ...(
const nested: {
property: Record<string, unknown>;
}
nested
.
property: Record<string, unknown>
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.