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).
backend ruleP2stack specificStack: typescript
typescripttype-narrowingcontrol-flow
Compare against string literals so TypeScript narrows the value
Direct === comparisons against literal values let TypeScript narrow the type, unlike a Set.has() check which leaves it as string.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | const allowed = new Set(['a', 'b', 'c']); |
| 2 | if (!allowed.has(value)) return next(); |
| 3 | // value is still string here |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | if (value !== 'a' && value !== 'b' && value !== 'c') return next(); |
| 2 | // value is now narrowed to 'a' | 'b' | 'c' |
Explanation (EN)
Objašnjenje (HR)