Skip to content

Bug: [consistent-type-assertions] autofix breaks type assertion of return value #6884

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
dora1998 opened this issue Apr 11, 2023 · 0 comments · Fixed by #6885
Closed
4 tasks done

Bug: [consistent-type-assertions] autofix breaks type assertion of return value #6884

dora1998 opened this issue Apr 11, 2023 · 0 comments · Fixed by #6885
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

@dora1998
Copy link
Contributor

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.0.3&sourceType=module&code=C4TwDgpgBAYg9nKBeKBvKAjAhgJwFxQB2ArgLYYQ4DcUAvgFADGchAzsFAB7JQAUAlMgB8UADzw4Q9NnxQArHSpA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6MgeyeUuX0Ra0ipWgENkyRNHyUuqDAG1IU6B2iQANJnDYc4ydNlMAykSToo4yDogBfALo7bIW0A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

type Foo = { bar: number; }
const x = () => <Foo>{ bar: 5 };

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/consistent-type-assertions": ["error", {
      "assertionStyle": "as",
    }],
  },
};

tsconfig

No response

Expected Result

I expected the following autofix.

type Foo = { bar: number; }
const x = () => ({ bar: 5 } as Foo);

Actual Result

The following autofix breaks TypeScript syntax.

type Foo = { bar: number; }
const x = () => { bar: 5 } as Foo;

Additional Info

Ref: #6641

@dora1998 dora1998 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 Apr 11, 2023
@bradzacher bradzacher 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 Apr 11, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 4, 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