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 ruleP1universalStack: typescript
typescriptnull-safetycorrectnessmaps
Guard dynamic map lookups with optional chaining and a fallback
When indexing a record by a runtime value, use optional chaining and provide a fallback so a missing key does not throw.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | const tabs = tabInstrumentMap[ticker.instrumentType].filter(/* throws if key missing */); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const tabs = (tabInstrumentMap[ticker.instrumentType] ?? []).filter(/* ... */); |
Explanation (EN)
Objašnjenje (HR)