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 ruleP1stack specificStack: typescript
typescriptexhaustivenesstype-safety
Make switch/case over a union exhaustive with a never guard
Require the discriminant type (e.g. an enum) to be non-optional, handle every case, and route the default to a function typed (x: never) so adding a new case becomes a compile error.
PR: frontpage-web · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | switch (type) { |
| 2 | case RESULT_TYPE.RECENT: return style.recent; |
| 3 | case RESULT_TYPE.TRENDING: return style.trending; |
| 4 | default: return ''; |
| 5 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | switch (type) { |
| 2 | case RESULT_TYPE.RECENT: return style.recent; |
| 3 | case RESULT_TYPE.TRENDING: return style.trending; |
| 4 | case RESULT_TYPE.INTERNAL: return ''; |
| 5 | default: return assertNever(type); |
| 6 | } |
| 7 | function assertNever(x: never): never { throw new Error(`Unhandled: ${x}`); } |
Explanation (EN)
Objašnjenje (HR)