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 ruleP2universalStack: TypeScript
architecturedrylayering
Return the final shape from its source rather than re-mapping downstream
If a repository/data method is the sole producer of a shape and nothing else consumes its raw form, have it return the final interface directly instead of mapping it again in the caller.
PR: hegnar-ws · org-mining-hist-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | const raw = await repo.getLatestMedia(); |
| 2 | const videos = raw.map((m) => ({ id: m.id, title: m.title, url: makeUrl(m.id) })); |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | // repo.getLatestMedia() already returns Video[] in final shape |
| 2 | const videos = await repo.getLatestMedia(); |
Explanation (EN)
Objašnjenje (HR)