Rules Hub
Code Ruleset
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
An endpoint that returns data should not be typed as void
If a handler responds with a payload, its return type must reflect that payload; a GET that produces data should not be declared to return void.
Bad example
| 1 | @Get('/top-contributor') |
| 2 | async getTopContributor(): Promise<void> { |
| 3 | return this.service.getTopContributor(); |
| 4 | } |
Explanation (EN)
A value-returning controller typed Promise<void> hides its returned DTO.
Objašnjenje (HR)
Good example
| 1 | @Get('/top-contributor') |
| 2 | async getTopContributor(): Promise<TopContributorDto> { |
| 3 | return this.service.getTopContributor(); |
| 4 | } |
Explanation (EN)
Objašnjenje (HR)
Notes (EN)
Match a controller method's return type to the value it actually returns under the framework's response contract.
Exceptions / Tradeoffs (EN)
A handler that calls res.json directly may correctly return void or Promise<void> even though the HTTP response contains data. Do not confuse a JavaScript return value with a response body.