Skip to content

[return-await] Fix result needs parentheses when code includes as cast #3613

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
3 tasks done
jtbandes opened this issue Jul 7, 2021 · 0 comments · Fixed by #3631
Closed
3 tasks done

[return-await] Fix result needs parentheses when code includes as cast #3613

jtbandes opened this issue Jul 7, 2021 · 0 comments · Fixed by #3631
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@jtbandes
Copy link
Contributor

jtbandes commented Jul 7, 2021

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/return-await": "error"
  }
}
function test<T>(): Promise<T> {
    const res = await fetch("...");
    try {
      return res.json() as Promise<T>;
    } catch (err) {
      throw new Error("Request Failed.");
    }
}

Expected Result
Fix result: return await (res.json() as Promise<T>);

Actual Result
Fix result: return await res.json() as Promise<T>;

This "fixed" code triggers the same lint error, and ESLint runs the fix multiple times, resulting in return await await ... await await res.json() as Promise<T>;.

Versions

package version
@typescript-eslint/eslint-plugin 4.28.2
@typescript-eslint/parser 4.28.2
TypeScript 4.3.5
ESLint 7.30.0
node 15.9.0
@jtbandes jtbandes added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jul 7, 2021
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels Jul 7, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2021
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
2 participants