Rules Hub
Coding Rules Library
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
fullstack ruleP1universalStack: TypeScript
validationtype-guardsdefensive-programmingapi
Validate the shape of an external response before trusting it
A 200 status does not guarantee the payload matches your interface. A type guard at the boundary stops a malformed upstream response from crashing the frontend; weigh this against consistency in your codebase.
PR: hegnar-components · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codets
| 1 | const data = await res.json(); |
| 2 | render(data.tickers); // assumes shape; throws if backend is wrong |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const data = await res.json(); |
| 2 | if (!isTickersResponse(data)) return []; |
| 3 | render(data.tickers); |
Explanation (EN)
Objašnjenje (HR)