Skip to content

Bug: [non-nullable-type-assertion-style] autofix does not account for await #7243

Closed
@G-Rath

Description

@G-Rath

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.1.6&fileType=.tsx&code=CYUwxgNghgTiAEAzArgOzAFwJYHtVK1WABEoMoAKASgC54AFGHAWywGcQAeNjGQgc3gAfeKmQQIAPgDcAWABQCsHh7xmAD3gBeeFDYBPdPGp1GLdlx59U-SdrsBvBfHhwMyGPgpQA7lCwYBESk5NRUumzwVgJy8gC%2BQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6JgeydqYXgEMARklpFStfsmSJo%2BSl1rIiSdFBnQO0SODABfELqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

declare function findData(): Promise<string | null>;

const mx = async () => {
  (await findData()) as string;
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/non-nullable-type-assertion-style": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

declare function findData(): Promise<string | null>;

const mx = async (): Promise<string> => {
  return (await findData())!;
}

Actual Result

declare function findData(): Promise<string | null>;

const mx = async (): Promise<string> => {
  return await findData()!;
}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething 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