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

Detect awaiting non-invoked functions? #521

Open
AlCalzone opened this issue Jan 9, 2019 · 1 comment
Open

Detect awaiting non-invoked functions? #521

AlCalzone opened this issue Jan 9, 2019 · 1 comment

Comments

@AlCalzone
Copy link

While enabling wotan for a project of mine, I found this gem:

await this.observeGroupsAndScenes; // Unnecessary 'await' of a non-Promise value. [await-only-promise]

where observeGroupsAndScenes is a function that returns a promise. While wotan helped me find this, (and the --fix option removed the await 😨), I think it could be smarter - in this case I forgot the parentheses:

await this.observeGroupsAndScenes(); // correct

Would it be possible to detect this and provide both errors?
Like "Unnecessary 'await' of a non-Promise value" OR "Did you forget parentheses?"

@ajafff
Copy link
Member

ajafff commented Jan 9, 2019

It's possible to detect this in most cases. If the return value is determined by an argument passed to the function, this won't be detected because obviously there are no arguments to infer the return type from.

The proposed behavior would check if the awaited expression is callable and if one of its call signatures (regardless of the parameters) is a valid PromiseLike. A return type of any and type parameters are not considered as PromiseLike.

and the --fix option removed the await 😨

Sorry for that.

I'm still planning to land #316 soon. This enables downgrading some fixes to suggested refactorings, which means they are not automatically applied. You could only use them through tools like the TypeScript LanguageService Plugin (which currently doesn't suggest fixes/refactorings at all).
After that is implemented all existing fixes need to be revisited and converted to a CodeAction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants