TypeScript · TS0010
Avoid copying growing reducer accumulators
Detect repeated accumulator copies in inline reduce and reduceRight callbacks.
typescript/performance/no-reduce-accumulator-copysrc/rule-packs/typescript/rules/no-reduce-accumulator-copy.ts Upstream docs 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.
Recommended fix
Use a fresh, locally owned accumulator and update it in place after reviewing ownership. Do not mutate shared initial state.
Useful links
Example
Avoid copying growing reducer accumulators
Before
items.reduce((acc, item) => acc.concat([item]), [])
After
items.reduce((acc, item) => { acc.push(item); return acc }, [])