Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Keep guaranteed fields non-nullable; fix the source instead of widening the type
Fix broken upstream invariants while validating real nullable boundary data; neither blanket widening nor dishonest types are safe.
Bad example
| 1 | // A stale cache sometimes returns name = null, so the type was loosened |
| 2 | interface UserBadgeProps { |
| 3 | name: string | null; // widened to silence the symptom |
| 4 | avatar: string; |
| 5 | } |
| 6 |
|
| 7 | function UserBadge({ name, avatar }: UserBadgeProps) { |
| 8 | // every consumer now has to defend against a null that shouldn't exist |
| 9 | return <span>{name ?? 'Unknown'}</span>; |
| 10 | } |
Explanation (EN)
Blindly widening every domain consumer can spread an upstream defect rather than isolate it.
Objašnjenje (HR)
Slijepo proširenje svih domenskih potrošača može proširiti grešku izvora umjesto da je izolira.
Good example
| 1 | // name is guaranteed present by the data contract; fix the cache, keep type honest |
| 2 | interface UserBadgeProps { |
| 3 | name: string; |
| 4 | avatar: string; |
| 5 | } |
| 6 |
|
| 7 | function UserBadge({ name, avatar }: UserBadgeProps) { |
| 8 | return <span>{name}</span>; |
| 9 | } |
Explanation (EN)
Keeping `name: string` reflects the actual guarantee, so consumers stay simple and TypeScript will flag any real source of null at the boundary where it must be fixed.
Objašnjenje (HR)
Zadržavanje `name: string` odražava stvarnu garanciju, pa korisnici ostaju jednostavni, a TypeScript će označiti svaki stvarni izvor null vrijednosti na granici gdje se mora popraviti.
Notes (EN)
Keep the validated domain model aligned with its intended invariant while fixing an upstream producer that violates it.
Exceptions / Tradeoffs (EN)
At the raw external boundary, model observed null honestly or reject it during validation. Do not keep an unsound string annotation merely to preserve a desired invariant; rollout must account for legacy records.
Iznimke / Tradeoffi (HR)
Na sirovoj vanjskoj granici pošteno modeliraj opaženi null ili ga odbij pri validaciji. Nemoj zadržati netočan string tip samo radi željene invarijante; objava mora uzeti u obzir stare zapise.