TypeScript · TS0010

Avoid copying growing reducer accumulators

Detect repeated accumulator copies in inline reduce and reduceRight callbacks.
TS0010vite-doctor/typescriptperformancewarnNo fix

Run this rule

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

Why it matters

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.

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 }, [])
Copyright © 2026