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 ruleP2universalStack: TypeScript
arraysclean-codemap-filtercorrectness
Filter out falsy entries before mapping to extract ids
When extracting a list of ids from records that may lack one, filter for the presence of the field first, then map, so the resulting array has no undefined entries.
PR: vinify-backend · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const recordIds = values.recordsList.map(el => el.id); // may include undefined |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const recordIds = values.recordsList.filter(el => el.id).map(el => el.id); |
Explanation (EN)
Objašnjenje (HR)