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
typesdefensive-codingcontractscorrectness
Enforce types in the signature, don't rely on callers' good will
An implementation should not depend on a caller always passing a string/number; type the parameter precisely so TypeScript guarantees it rather than assuming runtime values.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codets
| 1 | const { replyId } = req.query; // typed string | string[] |
| 2 | // 'we always send a string so casting is fine' |
| 3 | Service.adminDeleteReply(Number(replyId), ...); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | const replyId = req.query.replyId as string; // or validate it explicitly |
| 2 | Service.adminDeleteReply(Number(replyId), ...); |
Explanation (EN)
Objašnjenje (HR)