strict-void-functions
💼 This rule is enabled in the ✅ recommended
config.
Disallows non-empty return statements in functions annotated as returning void.
Rule Details​
void
is different from undefined
in that undefined
is a value and void
is the lack of any value. Thus, it is confusing if someone is explicitly returning undefined
from a function that is annotated as returning void
. In general, this is indication that either the return type of the function should be changed to undefined
or the predicate of the return
statement is superfluous.
// Bad
function foo(): void {
return undefined;
}
// Good
function foo(): void {
return;
}
// Good
function foo(): undefined {
return undefined;
}
Options​
This rule is not configurable.