Skip to content

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

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
4 tasks done
G-Rath opened this issue Jul 16, 2023 · 1 comment · Fixed by #7289
Closed
4 tasks done

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

G-Rath opened this issue Jul 16, 2023 · 1 comment · Fixed by #7289
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@G-Rath
Copy link
Contributor

G-Rath commented Jul 16, 2023

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

@G-Rath G-Rath added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Jul 16, 2023
@JoshuaKGoldberg
Copy link
Member

👍 Looks like another case where precedences aren't being respected. This should probably be fixed using util.getOperatorPrecedence.

@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Jul 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants