Rules Hub
Code Ruleset
← 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 ruleP2stack specificStack: TypeScript
typescriptenumconst-assertionidioms
Use an as const object instead of an enum for value-only constants
Prefer a const object for simple value-only groups when compatible; as const does not freeze the runtime object.
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)
An enum adds runtime machinery when only named literal values are required.
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)
Notes (EN)
For a value-only constant group, compare a const object with the project's enum convention and emitted JavaScript needs.
Exceptions / Tradeoffs (EN)
as const is compile-time readonly inference, not Object.freeze or deep runtime immutability. Numeric enums have reverse mappings; changing representation can affect consumers.