Should disallow using the result of calling a void-returning function #40997
Labels
Awaiting More Feedback
This means we'd like to hear from more people who would be helped by this feature
Suggestion
An idea for TypeScript
TypeScript Version: 4.1.0-dev.20201008
Search Terms: disallow function call void return usage warn error
Code
Expected behavior:
The expression
doesntReturn() + 'foo'
should be an error because it uses the value of avoid
-returning function call. As far as I can tell, there is literally no good reason to use the return value of a function with no return statements like this.This is similar to the current behavior of disallowing void-returning expressions inside control flow (issue #26262). It is also similar to the reasoning behind the warning that occurs when using a function value (instead of calling it) in an
if
condition.Actual behavior:
No error message is given.
Playground Link: here
Related Issues: #26262
The text was updated successfully, but these errors were encountered: