# Source: https://oxc.rs/docs/guide/usage/linter/rules/unicorn/no-useless-spread.md

---
url: /docs/guide/usage/linter/rules/unicorn/no-useless-spread.md
---

### What it does

Disallows using spread syntax in following, unnecessary cases:

* Spread an array literal as elements of an array literal
* Spread an array literal as arguments of a call or a `new` call
* Spread an object literal as properties of an object literal
* Use spread syntax to clone an array created inline

### Why is this bad?

The following builtins accept an iterable, so it's unnecessary to
convert the iterable to an array:

* `Map` constructor
* `WeakMap` constructor
* `Set` constructor
* `WeakSet` constructor
* `TypedArray` constructor
* `Array.from(…)`
* `TypedArray.from(…)`
* `Promise.{all,allSettled,any,race}(…)`
* `Object.fromEntries(…)`

The `for…of` loop can iterate over any iterable object not just array,
so it's unnecessary to convert the iterable to an array.

The `yield*` can delegate to another iterable, so it's unnecessary to
convert the iterable to an array.

### Examples

Examples of **incorrect** code for this rule:

```javascript
const array = [firstElement, ...[secondElement], thirdElement];

await Promise.all([...iterable]);

for (const foo of [...set]);

function* foo() {
  yield* [...anotherGenerator()];
}

function foo(bar) {
  return [...bar.map((x) => x * 2)];
}
```

Examples of **correct** code for this rule:

```javascript
const array = [firstElement, secondElement, thirdElement];

await Promise.all(iterable);

for (const foo of set);

function* foo() {
  yield* anotherGenerator();
}

function foo(bar) {
  return bar.map((x) => x * 2);
}
```

## How to use

To **enable** this rule using the config file or in the CLI, you can use:

::: code-group

```json [Config (.oxlintrc.json)]
{
  "rules": {
    "unicorn/no-useless-spread": "error"
  }
}
```

```bash [CLI]
oxlint --deny unicorn/no-useless-spread
```

:::

## References

* Rule Source