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 ruleP1stack specificStack: typescript
typescriptnull-safetytypessemantics
Model null and undefined as distinct states when they mean different things
Use null for an explicit empty/failed value and undefined for not-yet-set, and type accordingly when the two cases must be handled differently.
PR: hegnar-forum-web · org-mining-2026-06Created: Jun 17, 2026
Bad example
Old codets
| 1 | // collapses two distinct cases into one |
| 2 | type State = Data | undefined; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | // null = endpoint failed, undefined = never provided |
| 2 | type State = Data | null | undefined; |
Explanation (EN)
Objašnjenje (HR)