Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Define types for third-party API responses
Write explicit types for external/provider API responses (per their docs) instead of leaving them untyped.
Bad example
| 1 | const data = await response.json(); // any |
Explanation (EN)
An any result permits unchecked fields and wrong type assumptions.
Objašnjenje (HR)
Good example
| 1 | interface MetricsResponse { id: string; views: number; } |
| 2 | const raw: unknown = await response.json(); |
| 3 | const data: MetricsResponse = parseMetricsResponse(raw); |
Explanation (EN)
The parser verifies the external fields and domain ranges before returning the named response type.
Objašnjenje (HR)
Notes (EN)
Define or derive a schema for the provider's actual response, then validate unknown payloads before treating them as the internal type.
Exceptions / Tradeoffs (EN)
A TypeScript interface or assignment annotation alone performs no runtime validation. Handle provider version drift, optional fields and numeric/date representations explicitly.