TypeScript · performance

TS0012Review adjacent eager array transformations

Detect adjacent filter/map or map/filter passes on locally evidenced arrays.

Why it happens

Adjacent eager passes allocate an intermediate array. This optional policy reports only array literals, direct array annotations, immutable aliases, and supported array-preserving calls. Imported factories, property types, and generic aliases are not inferred. Iterator helpers are not guaranteed faster.

Fix

Review a single transformation or supported iterator helpers, preserving callback order, indexes, thisArg, and sparse-array behavior. Check target runtime support before using iterator helpers.

Example

Review adjacent eager array transformations

Before

const values = [1, 2, 3].filter(value => value > 1).map(value => value * 2)

After

const values = [1, 2, 3].values().filter(value => value > 1).map(value => value * 2).toArray()

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-array-filter-map
Copyright © 2026