Skip to content

Error for missing await in conditional #25330

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

Closed
mjbvz opened this issue Jun 30, 2018 · 3 comments · Fixed by #39175
Closed

Error for missing await in conditional #25330

mjbvz opened this issue Jun 30, 2018 · 3 comments · Fixed by #39175
Labels
Breaking Change Would introduce errors in existing code In Discussion Not yet reached consensus Suggestion An idea for TypeScript

Comments

@mjbvz
Copy link
Contributor

mjbvz commented Jun 30, 2018

TypeScript Version: 3.0.0-dev.20180626

Search Terms:

  • await
  • conditional
  • diagnostics

Code

async function foo(): Promise<boolean> {
    return false;
}

async function bar(): Promise<string> {
    if (foo()) {
        return 'true';
    }
    return 'false';
}

Expected behavior:
A warning or error or suggestion is generated in the if conditional since it will always be true. The user almost certainly intended to await the result of foo instead.

Possibly also have a quick fix to add the await

Actual behavior:
No errors or warnings. Code does unexpected things

@mhegazy mhegazy added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Jun 30, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jun 30, 2018

This is in the realm of linter work, but i suppose we can make an exception here since this code will never work anyways..

@dpinol
Copy link

dpinol commented Oct 11, 2019

After the work done in TS3.6 "Improved UX Around Promises" this shouldn't be difficult to implement right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Breaking Change Would introduce errors in existing code In Discussion Not yet reached consensus Suggestion An idea for TypeScript
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@DanielRosenwasser @dpinol @mhegazy @mjbvz and others