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 ruleP1stack specificStack: typescript
typesnull-safetyapi-design
Make return types reflect that null is possible
If a function can return null because its inputs are nullable, annotate the return type as nullable instead of claiming a non-null type.
PR: hegnar-mws · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | getPrice(item: PriceInput): number { |
| 2 | return item.value; // item.value is number | null |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | getPrice(item: PriceInput): number | null { |
| 2 | return item.value; |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)