Rules Hub
Coding Rules Library
Avoid naming files 'Types' if they export runtime values
Files named '*.types.ts' should strictly contain type definitions. If they export runtime values, rename them to '*.constants.ts' or the domain name.
Bad example
| 1 | // src/components/ArticleTypes.ts |
| 2 |
|
| 3 | export interface Article { |
| 4 | id: string; |
| 5 | title: string; |
| 6 | } |
| 7 |
|
| 8 | // Bad: This is a runtime value in a 'Types' file |
| 9 | export const ARTICLE_CATEGORIES = ['News', 'Sports', 'Tech']; |
Explanation (EN)
The filename 'ArticleTypes' suggests it only contains TypeScript definitions and will be erased at runtime. Including runtime constants like 'ARTICLE_CATEGORIES' violates this expectation.
Objašnjenje (HR)
Naziv datoteke 'ArticleTypes' sugerira da ona sadrži samo TypeScript definicije i da će biti obrisana pri kompajliranju. Uključivanje 'runtime' konstanti poput 'ARTICLE_CATEGORIES' krši to očekivanje.
Good example
| 1 | // src/components/ArticleConstants.ts |
| 2 |
|
| 3 | // Good: The filename reflects that it contains values |
| 4 | export interface Article { |
| 5 | id: string; |
| 6 | title: string; |
| 7 | } |
| 8 |
|
| 9 | export const ARTICLE_CATEGORIES = ['News', 'Sports', 'Tech']; |
Explanation (EN)
Renaming the file to 'ArticleConstants' (or just 'Article') correctly indicates that it exports runtime values alongside types.
Objašnjenje (HR)
Preimenovanje datoteke u 'ArticleConstants' (ili samo 'Article') ispravno naznačuje da ona izvozi 'runtime' vrijednosti uz tipove.