Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should disallow using the result of calling a void-returning function #40997

Open
drmercer-lucid opened this issue Oct 8, 2020 · 0 comments
Open
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

Comments

@drmercer-lucid
Copy link

TypeScript Version: 4.1.0-dev.20201008

Search Terms: disallow function call void return usage warn error

Code

function doesntReturn() {
    // no return statement
}

const foo: string = doesntReturn() + 'foo'; // should be an error

Expected behavior:

The expression doesntReturn() + 'foo' should be an error because it uses the value of a void-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

@andrewbranch andrewbranch added 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 labels Oct 9, 2020
@andrewbranch andrewbranch modified the milestone: Backlog Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants