Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Type a constant array explicitly rather than asserting with as const
Choose a readonly array or const tuple according to the desired type information; as const is not inherently wrong.
Bad example
| 1 | export const dataAlignmentOptions = ['left', 'center', 'right'] as const; |
Explanation (EN)
A const tuple can be too narrow only when callers need the broader readonly array contract.
Objašnjenje (HR)
Good example
| 1 | export type Alignment = 'left' | 'center' | 'right'; |
| 2 | export const alignmentOptions: readonly Alignment[] = ['left', 'center', 'right']; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Use readonly T[] when the contract is an arbitrary immutable-by-type list of T; retain a const tuple when exact values/positions should drive types.
Exceptions / Tradeoffs (EN)
as const preserves literal/tuple information, while an annotation may widen it. Neither freezes nested runtime data. Do not replace useful literal inference merely for style.