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).
Extract complex generic callback signatures into named type aliases
Do not inline non-trivial generic callback types in props or exported interfaces.
Bad example
| 1 | type FormFields = { |
| 2 | name: string; |
| 3 | age: number; |
| 4 | }; |
| 5 |
|
| 6 | interface Props { |
| 7 | onChange: <K extends keyof FormFields>(field: K, value: FormFields[K]) => void; |
| 8 | } |
Explanation (EN)
Inlining a generic callback signature makes the public contract harder to scan, harder to reuse, and more tedious to discuss in review.
Objašnjenje (HR)
Inline genericki callback potpis oteza brzo citanje javnog kontrakta, teze ga je ponovno koristiti i neugodniji je za review raspravu.
Good example
| 1 | type FormFields = { |
| 2 | name: string; |
| 3 | age: number; |
| 4 | }; |
| 5 |
|
| 6 | type FieldChangeHandler = <K extends keyof FormFields>(field: K, value: FormFields[K]) => void; |
| 7 |
|
| 8 | interface Props { |
| 9 | onChange: FieldChangeHandler; |
| 10 | } |
Explanation (EN)
A named alias gives the contract a reusable label and keeps the interface focused on intent instead of type noise.
Objašnjenje (HR)
Imenovani alias daje ugovoru ponovno iskoristivo ime i drzi interface fokusiranim na namjeru umjesto na tipovni sum.
Exceptions / Tradeoffs (EN)
Keep simple inline function types inline when they have no generics and remain easy to read.
Iznimke / Tradeoffi (HR)
Jednostavne inline funkcijske tipove ostavi inline kada nemaju generike i ostaju laki za citanje.