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
typescripttypesreturn-typeapi-design
Tighten return types that are never actually null
If a function always returns a value, do not annotate its return type as nullable; remove the unnecessary `| null` so callers are not forced into defensive checks for an impossible case.
PR: hegnar-forum-web · org-mining-3rd-2026-06Created: Jun 18, 2026
Bad example
Old codetypescript
| 1 | async function getReports(): Promise<{ statusCode: number; payload: Payload | null } | null> { |
| 2 | return { statusCode: 200, payload }; |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)
Good example
New codetypescript
| 1 | async function getReports(): Promise<{ statusCode: number; payload: Payload | null }> { |
| 2 | return { statusCode: 200, payload }; |
| 3 | } |
Explanation (EN)
Objašnjenje (HR)