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).
frontend ruleP1stack specificStack: typescript
typescriptnull-safetycorrectness
Narrow nullable values before numeric comparisons
Check the type/presence of a possibly-undefined value before comparing it numerically, rather than relying on coercion or comparing undefined against numbers.
PR: hegnar-zephr-components · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetsx
| 1 | {numberOfReplies >= 0 && <Count value={numberOfReplies} />} |
| 2 | // numberOfReplies can be undefined |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetsx
| 1 | {typeof numberOfReplies === 'number' && numberOfReplies >= 0 && ( |
| 2 | <Count value={numberOfReplies} /> |
| 3 | )} |
Explanation (EN)
Objašnjenje (HR)