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: node
expresstypescripttype-safetyrouting
Type each route's req/res with the exact extended shape it needs
Extend Request/Response per route with the specific query, params and locals used, instead of one global type carrying many optional properties.
PR: hegnar-web · org-mining-hist-2026-06Created: Jun 19, 2026
Bad example
Old codetypescript
| 1 | // global Response.locals with everything optional |
| 2 | const handler = (req: Request, res: Response) => { |
| 3 | const token = res.locals.xMwsToken; // any |
| 4 | }; |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | interface ChartRequest extends Request { query: { filter: DateFilter } } |
| 2 | interface MwsResponse extends Response { locals: { xMwsToken: string } } |
| 3 | const handler = (req: ChartRequest, res: MwsResponse) => { |
| 4 | const token = res.locals.xMwsToken; // string |
| 5 | }; |
Explanation (EN)
Objašnjenje (HR)