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 ruleP2universalStack: typescript
readabilityrecordlookup-tabletypes
Replace mode-to-string conditionals with a typed Record lookup
Map a small fixed set of keys to values via a typed Record instead of a function full of if/switch branches.
PR: hegnar-journalist-boost · org-mining-deep-2026-06Created: Jun 17, 2026
Bad example
Old codetypescript
| 1 | function label(mode: Mode) { |
| 2 | if (mode === 'edit') return 'Edit mode'; |
| 3 | if (mode === 'view') return 'View mode'; |
| 4 | return 'Suggest mode'; |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const labels: Record<Mode, string> = { |
| 2 | edit: 'Edit mode', view: 'View mode', suggest: 'Suggest mode', |
| 3 | }; |
| 4 | const label = labels[mode]; |
Explanation (EN)
Objašnjenje (HR)