Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Only create types that narrow or clarify
A new type alias should either add compile-time constraints or preserve domain meaning. If it does neither, use the primitive directly.
Bad example
| 1 | export type PortfolioCashTransactionType = string; |
| 2 |
|
| 3 | export interface CashTransactionItem { |
| 4 | type: PortfolioCashTransactionType; |
| 5 | } |
| 6 |
|
| 7 | interface GetPortfolioTransactionsProps { |
| 8 | order?: PortfolioTransactionOrder | null; |
| 9 | page?: number | null; |
| 10 | take?: number | null; |
| 11 | } |
Explanation (EN)
The alias adds no safety because it is still just string, and the optional-plus-null fields add extra states without different semantics. The contract becomes weaker, not clearer.
Objašnjenje (HR)
Alias ne dodaje sigurnost jer je i dalje samo string, a optional-plus-null polja dodaju dodatna stanja bez razlicitog znacenja. Contract postaje slabiji, a ne jasniji.
Good example
| 1 | export type StockTransactionType = 'Kjop' | 'Salg'; |
| 2 |
|
| 3 | export interface CashTransactionItem { |
| 4 | type: string; |
| 5 | } |
| 6 |
|
| 7 | interface GetPortfolioTransactionsProps { |
| 8 | order?: PortfolioTransactionOrder; |
| 9 | page?: number; |
| 10 | take?: number; |
| 11 | } |
Explanation (EN)
Use a union when the set is real and stable. Use the primitive directly when the value is effectively free-form. Prefer undefined over null when omission already means not provided.
Objašnjenje (HR)
Koristi union kada je skup stvaran i stabilan. Koristi primitiv direktno kada je vrijednost prakticki free-form. Preferiraj undefined umjesto null kada izostavljanje vec znaci not provided.
Notes (EN)
Before adding a new alias, ask: does this constrain values, document a domain boundary, or improve call-site clarity?
Bilješke (HR)
Prije dodavanja novog aliasa pitaj: ogranicava li ovo vrijednosti, dokumentira li domensku granicu ili poboljsava li jasnoce na call siteu?
Exceptions / Tradeoffs (EN)
A domain alias is still useful when it reuses a shared primitive but keeps a meaningful API surface, for example `type PortfolioTransactionOrder = SortOrderUpper`.
Iznimke / Tradeoffi (HR)
Domenski alias je i dalje koristan kada ponovno koristi shared primitiv, ali zadrzava smislen API surface, npr. `type PortfolioTransactionOrder = SortOrderUpper`.