Skip to content

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

Closed
@dora1998

Description

@dora1998

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

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