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).
fullstack ruleP2stack specificStack: typescript
typescripttypesreadabilitynull-safety
Add explicit types to variables whose value can be one of several types
When a variable can hold more than one type (e.g. number or null), give it an explicit type annotation rather than relying on inference.
PR: vinify-frontend · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codets
| 1 | const glassCost = price && volume && size ? price * (size / volume) : null; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const glassCost: number | null = price && volume && size ? price * (size / volume) : null; |
Explanation (EN)
Objašnjenje (HR)