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).
Name a repeated Omit<>/Pick<> utility-type expression instead of spelling it out twice
If the same `Omit<Interface, 'a' | 'b' | 'c'>` (or similar derived-type expression) appears in more than one place, give it a name once. Otherwise changing the underlying interface requires editing every call site in lockstep, and a missed one surfaces as a type error far from the actual change.
Bad example
| 1 | // file A |
| 2 | function toMobile(a: IAuthor): Omit<IAuthor, 'jobTitle' | 'profileText' | 'twitter'> { ... } |
| 3 |
|
| 4 | // file B — same shape, spelled out again |
| 5 | interface Entity { |
| 6 | asMobileJSON(): Omit<IAuthor, 'jobTitle' | 'profileText' | 'twitter'>; |
| 7 | } |
Explanation (EN)
The same set of omitted keys is duplicated verbatim. Adding a field to IAuthor and forgetting to also omit it in one of the two places produces a type mismatch that's confusing to trace back to its source.
Objašnjenje (HR)
Isti skup izostavljenih ključeva dupliciran je doslovno. Dodavanje polja u IAuthor i zaboravljanje da ga se izostavi na jednom od dva mjesta stvara neslaganje tipova koje je teško pratiti do izvora.
Good example
| 1 | type IMobileAuthor = Omit<IAuthor, 'jobTitle' | 'profileText' | 'twitter'>; |
| 2 |
|
| 3 | function toMobile(a: IAuthor): IMobileAuthor { ... } |
| 4 |
|
| 5 | interface Entity { |
| 6 | asMobileJSON(): IMobileAuthor; |
| 7 | } |
Explanation (EN)
The omitted-keys list exists once. Every consumer references the named type, so a future change to IAuthor only needs updating in one spot.
Objašnjenje (HR)
Popis izostavljenih ključeva postoji samo jednom. Svaki korisnik referencira imenovani tip, pa buduća promjena IAuthor sučelja zahtijeva ažuriranje samo na jednom mjestu.