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).
Verify every field consumers read still exists when you switch the data source
Repointing a call at a new backend usually changes field names too, and optional chaining plus a default turns each renamed field into an empty value that renders as blank instead of failing.
Bad example
| 1 | // Old service returned { symbol, name }; the new one returns { symbol, fullName, logoUrl } |
| 2 | const tags = await newService.getTickerTags(id); |
| 3 |
|
| 4 | // Untouched consumer - `name` no longer exists, so this silently renders empty |
| 5 | <TickerTag name={article.tickerTags[0]?.name ?? ""} /> |
Explanation (EN)
The optional chain and the default absorb the missing field, so the UI renders a blank label instead of surfacing that the contract changed.
Objašnjenje (HR)
Opcijski lanac i zadana vrijednost apsorbiraju polje koje nedostaje, pa sucelje prikazuje prazan natpis umjesto da otkrije promjenu ugovora.
Good example
| 1 | interface TickerTag { |
| 2 | symbol: string; |
| 3 | fullName: string; |
| 4 | logoUrl: string | null; |
| 5 | } |
| 6 |
|
| 7 | const tags: TickerTag[] = await newService.getTickerTags(id); |
| 8 |
|
| 9 | // Consumer updated in the same change; `name` would now be a compile error |
| 10 | <TickerTag name={article.tickerTags[0]?.fullName ?? ""} /> |
Explanation (EN)
The response is typed against the new contract, so every consumer reading a removed field fails to compile and gets updated in the same change.
Objašnjenje (HR)
Odgovor je tipiziran prema novom ugovoru, pa svaki potrosac koji cita uklonjeno polje ne prolazi prevodenje i azurira se u istoj promjeni.
Notes (EN)
Grep for every property the old response exposed before switching. Defaulted optional chains are exactly where a rename hides, because nothing throws.
Bilješke (HR)
Prije zamjene pretrazi svako svojstvo koje je stari odgovor nudio. Opcijski lanci sa zadanim vrijednostima upravo su mjesto gdje se preimenovanje skriva jer nista ne baca gresku.