Skip to content

[return-await] False positive on any return type, e.g. return JSON.parse() #1269

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
felixfbecker opened this issue Nov 26, 2019 · 1 comment · Fixed by #1270
Closed

[return-await] False positive on any return type, e.g. return JSON.parse() #1269

felixfbecker opened this issue Nov 26, 2019 · 1 comment · Fixed by #1270
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@felixfbecker
Copy link

felixfbecker commented Nov 26, 2019

Repro

{
  "rules": {
    "@typescript-eslint/return-await": "error"
  }
}
async function fetcher(): Promise<string> {
    const response = await fetch('/.api/graphql')
    const responseBody = await response.text()
    try {
        return JSON.parse(responseBody)
    } catch (error) {
        return responseBody
    }
}

Expected Result

No error, as JSON.parse() does not return a Promise.

Actual Result

Error: returning an awaited promise is required in this context

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.9.0
@typescript-eslint/parser 2.9.0
TypeScript 3.7.2
ESLint 6.6.0
node 12
@felixfbecker felixfbecker added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 26, 2019
@bradzacher
Copy link
Member

Hmm, I missed this in the PR, but it looks like the rule was built this way to treat any and unknown as awaitable.

This shouldn't be the case (as per the decisions made for promise-function-async).

@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Nov 26, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants