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).
backend ruleP1stack specificStack: typescript
typesapi-integrationcorrectnessvalidation
Match interface field types to the actual API payload
Confirm the runtime type a third-party API returns (e.g. an id may arrive as a string, not a number) before declaring the field, and convert explicitly when you need a different type.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codets
| 1 | interface UserAttributes { forum_id: number; } |
| 2 | const json: UserAttributes = await res.json(); |
| 3 | return json.forum_id ?? null; // actually a string at runtime |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | interface UserAttributes { forum_id: string; } |
| 2 | const json: UserAttributes = await res.json(); |
| 3 | return json.forum_id ? Number(json.forum_id) : null; |
Explanation (EN)
Objašnjenje (HR)