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 ruleP2universalStack: TypeScript
typescriptenumconst-assertionidioms
Use an as const object instead of an enum for value-only constants
When a set of constants is used only as values (never as a type), a frozen object literal with as const is lighter and more idiomatic than a TS enum.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | enum NoContentText { |
| 2 | SOMETHING_WENT_WRONG = 'Noe gikk galt', |
| 3 | NO_RESULTS = 'Ingen resultater', |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | export const NoContentText = { |
| 2 | SOMETHING_WENT_WRONG: 'Noe gikk galt', |
| 3 | NO_RESULTS: 'Ingen resultater', |
| 4 | } as const; |
Explanation (EN)
Objašnjenje (HR)