# prefer-spread

> Require spread syntax instead of `.apply()` to pass an array as arguments

`Math.max.apply(Math, values)` only uses `.apply()` to pass an array as separate arguments, and it has to repeat `Math` to keep `this`. `Math.max(...values)` does the same thing and reads like a normal call.

A call is only reported if spread can replace it, so `.apply()` must leave `this` the way a plain call would. That means `null` or `undefined` for a function, and the same object for a method.

This rule is on by default in TypeScript files.

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

## Configure

On by default as a warning. To turn it off:

```toml bunfig.toml
[lint.rules]
"prefer-spread" = "off" # or "error"
```

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

## Examples

Reported:

{/* bad {"count": 3} */}
```js
const highest = Math.max.apply(Math, values);
notify.apply(null, listeners);
logger.info.apply(logger, parts);
```

Not reported:

{/* good */}
```js
const highest = Math.max(...values);
notify(...listeners);
logger.info(...parts);

// Sets another `this`, which spread cannot do
render.apply(view, parts);
logger.info.apply(console, parts);
```
