# unicorn/no-useless-fallback-in-spread

> Disallow an empty object as the fallback when spreading into an object literal

Spreading `undefined` or `null` into an object literal adds nothing and doesn't throw. So `{ ...(options || {}) }` and `{ ...(options ?? {}) }` give the same object as `{ ...options }`.

This is only true for objects. Spreading `undefined` into an array or a call's arguments throws, so `[...(items || [])]` isn't reported.

`--fix` removes the fallback.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"unicorn/no-useless-fallback-in-spread" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
function request(url, options, extraHeaders) {
  const headers = { accept: "application/json", ...(extraHeaders || {}) };
  return fetch(url, { ...(options ?? {}), headers });
}
```

Not reported:

{/* good */}
```js
function request(url, options, extraHeaders) {
  const headers = { accept: "application/json", ...extraHeaders };
  return fetch(url, { ...options, headers });
}

// the fallback has something in it
const settings = { ...(saved || { theme: "light" }) };

// arrays need the fallback
const all = [...(items || [])];
```
