-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Compiler suggestion: explicitly await #10381
Comments
There are many valid things to do with an async function other than awaiting it. It's just a function that returns a promise, after all. So you may want to explicitly assign that promise to a variable or push it into an array and then use Perhaps rather than looking for an explicit |
With type annotations the error is easily spotted, e.g. the compiler will warn if you are trying to use a |
The problem is that, as noted, there are an infinite number of valid ways to "correctly" handle a Promise (and people will have varying definitions of "correct", including those who want to conditionally not await something ever!). If you want to enforce in your project that you only handle them in a finite set of allowed ways, that's a good candidate for a TSLint rule. |
looks like someone is already trying to write it: palantir/tslint#892 |
Oh, yes. Adding it to linting is definitely a good idea. I just thought it might be able to be implemented as an "unused variable/value" type warning. Linting works for us, though. |
I'm not incredibly familiar with the compiler's internals, so if someone wants to rewrite this suggestion as a proposal, go ahead!
I've noticed it is quite easy for a developer to call an async function/method without awaiting on it, so it would be nice to have a compiler option similar to noimplicitany;noimplicitreturns; etc, where a developer has to explicitly declare that they wish to call an async function/method without awaiting on it.
This would help keep developers aware that the function/method is asynchronous so that they don't accidentally call it without awaiting on it.
The text was updated successfully, but these errors were encountered: