Rules Hub
Code Ruleset
← Back to all rules
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
frontend ruleP2stack specificStack: typescript
typescriptreturn-typevoidcleanup
Do not return null from functions typed to return void
When a function's declared return type is void, drop the explicit `return null` since it contradicts the signature.
PR: hegnar-forum-web · org-mining-hist-2026-06Created: Jun 20, 2026
Bad example
Old codetypescript
| 1 | const handleSubmit = async (data): Promise<void> => { |
| 2 | await save(data); |
| 3 | return null; |
| 4 | }; |
Explanation (EN)
The explicit null conflicts with the stated no-result contract and can mislead callers.
Objašnjenje (HR)
Good example
New codetypescript
| 1 | const handleSubmit = async (data): Promise<void> => { |
| 2 | await save(data); |
| 3 | }; |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
For a function declared void or Promise<void>, inspect callers before removing a terminal null return. Confirm no caller depends on the runtime null value.
Exceptions / Tradeoffs (EN)
A callback assignable to () => void can still return a meaningful value at runtime. Fix its contract rather than deleting data used elsewhere.