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).
Export every type referenced by an exported type
If an exported interface/type references nested types, export those too; otherwise declaration emit breaks with 'private name' errors and consumers can't use the public API type.
Bad example
| 1 | export interface ApiResponse { |
| 2 | user: User; |
| 3 | orders: Order[]; |
| 4 | } |
| 5 |
|
| 6 | type User = { id: string; name: string }; |
| 7 | type Order = { id: string; total: number }; |
Explanation (EN)
ApiResponse is exported but User and Order are not, so .d.ts emission fails and consumers cannot reference the User/Order shapes they receive.
Objašnjenje (HR)
ApiResponse je izvezen, ali User i Order nisu, pa emisija .d.ts puca, a potrosaci ne mogu referencirati oblike User/Order koje primaju.
Good example
| 1 | export interface ApiResponse { |
| 2 | user: User; |
| 3 | orders: Order[]; |
| 4 | } |
| 5 |
|
| 6 | export type User = { id: string; name: string }; |
| 7 | export type Order = { id: string; total: number }; |
Explanation (EN)
Every type reachable from the exported ApiResponse is itself exported, so declaration emit succeeds and consumers can import each nested type.
Objašnjenje (HR)
Svaki tip dostupan iz izvezenog ApiResponse je i sam izvezen, pa emisija deklaracija uspijeva, a potrosaci mogu uvesti svaki ugnijezdeni tip.
Exceptions / Tradeoffs (EN)
Truly internal helper types used only inside the module need not be exported as long as no exported type references them.
Iznimke / Tradeoffi (HR)
Doista interni pomocni tipovi koristeni samo unutar modula ne moraju biti izvezeni dok ih nijedan izvezeni tip ne referencira.