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).
Don't Export Cross-Cutting Types From a Component File
Types/interfaces used by both a component and a service belong in the shared interfaces/types folder, not exported out of the component.
Bad example
| 1 | // components/InstrumentCard/InstrumentCard.tsx |
| 2 | export interface InstrumentTableRow { |
| 3 | id: number; |
| 4 | name: string; |
| 5 | } |
| 6 |
|
| 7 | const InstrumentCard: FC<{ row: InstrumentTableRow }> = ({ row }) => { /* ... */ }; |
| 8 | export default InstrumentCard; |
| 9 |
|
| 10 | // utils/static/ticker-system/fetch/getInstruments.ts |
| 11 | import { InstrumentTableRow } from 'components/InstrumentsPage/InstrumentCard'; |
Explanation (EN)
Defines a domain type inside a UI component file and then imports it from a service/fetch module, coupling backend-adjacent code to a specific component's file location and making the component harder to move or delete.
Objašnjenje (HR)
Definira domenski tip unutar filea UI komponente i zatim ga importa iz service/fetch modula, čime se kod blizak backendu veže uz lokaciju konkretnog component filea, otežavajući premještanje ili brisanje te komponente.
Good example
| 1 | // interfaces/Instrument.ts |
| 2 | export interface InstrumentTableRow { |
| 3 | id: number; |
| 4 | name: string; |
| 5 | } |
| 6 |
|
| 7 | // components/InstrumentCard/InstrumentCard.tsx |
| 8 | import { InstrumentTableRow } from 'interfaces/Instrument'; |
| 9 |
|
| 10 | // utils/static/ticker-system/fetch/getInstruments.ts |
| 11 | import { InstrumentTableRow } from 'interfaces/Instrument'; |
Explanation (EN)
Moves the shared type into the project's dedicated interfaces folder so both the component and the service import it from a neutral, stable location instead of from each other.
Objašnjenje (HR)
Premješta zajednički tip u namjenski interfaces folder u projektu, tako da i komponenta i servis importaju iz neutralne, stabilne lokacije umjesto jedno iz drugoga.