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 ruleP2stack specificStack: typescript
typescripttypesapimodeling
Create a dedicated type for an endpoint-specific response
Rather than reusing a broad domain type full of optional fields, define a focused interface (e.g. TopCategoriesResponse) for a response that has its own shape.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codets
| 1 | // reuse Category, which has several optional fields, for the top-categories endpoint |
| 2 | function getTopCategories(): Promise<Category[]> {} |
Explanation (EN)
Objašnjenje (HR)
Good example
New codets
| 1 | interface TopCategory { id: number; name: string; count: number; } |
| 2 | interface TopCategoriesResponse { categories: TopCategory[]; } |
| 3 |
|
| 4 | function getTopCategories(): Promise<TopCategoriesResponse | null> {} |
Explanation (EN)
Objašnjenje (HR)