Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
backend ruleP2stack specificStack: typescript
typesreducegenericsindex-signature
Give reduce an explicit accumulator type when adding dynamic keys
Pass a generic to reduce (e.g. Record<string, T>) so dynamically-keyed accumulators do not trigger implicit-any index errors.
PR: vinify-backend · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | const acc = items.reduce((a, x, i) => { a[`k${i}`] = x; return a; }, { id }); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const acc = items.reduce<Record<string, string | number>>((a, x, i) => { a[`k${i}`] = x; return a; }, { id }); |
Explanation (EN)
Objašnjenje (HR)