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
readabilitytype-coercionnumbers
Cast strings to numbers with Number() rather than unary plus
Use the explicit Number(value) cast instead of the terse `+value` so the intent of converting a string param to a number is clear.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | const { id } = req.query; // string | string[] |
| 2 | const result = await service.update(req.body, +id); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const { id } = req.query; // string | string[] |
| 2 | const result = await service.update(req.body, Number(id)); |
Explanation (EN)
Objašnjenje (HR)