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
typescripttypesdomain-modeling
Narrow types to the set of values that can actually occur
Don't widen an enum/union to include values that the consumer can never receive; list only the values that are actually possible.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | // Sidebar can only ever show 4 link types, |
| 2 | // but the map allows any of 10 element kinds |
| 3 | const trackingMap: Record<SidebarElement, string> = { /* all 10 */ }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | // Restrict to the 4 links the sidebar can actually render |
| 2 | type SidebarLink = 'teknisk_analyse' | 'bjellesauer' | 'topp50' | 'historikk'; |
| 3 | const trackingMap: Record<SidebarLink, string> = { /* only 4 */ }; |
Explanation (EN)
Objašnjenje (HR)