Skip to content

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

Closed
@jtbandes

Description

@jtbandes
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions