TypeScript · performance

TS0010Avoid copying growing reducer accumulators

Detect repeated accumulator copies in inline reduce and reduceRight callbacks.

Why it happens

Copying accumulated state on every iteration can cause quadratic work as the accumulator grows. This rule covers Object.assign, Array.from, and array copy methods with local array evidence. It does not prove receiver types or accumulator growth; bounded copies may be intentional. Spreads and named callbacks are outside its scope.

Fix

Use a fresh, locally owned accumulator and update it in place after reviewing ownership. Do not mutate shared initial state.

Example

Avoid copying growing reducer accumulators

Before

items.reduce((acc, item) => acc.concat([item]), [])

After

items.reduce((acc, item) => { acc.push(item); return acc }, [])

Verify the fix

Run only this rule after editing so the report stays focused on the diagnostic you are closing:

pnpm vite-doctor . --extends auto,typescript/strict --rules typescript/performance/no-reduce-accumulator-copy
Copyright © 2026