Skip to content

Bug: consistent-type-definitions leaves trailing parenthesis when converting a paren-wrapped type to an interface #10233

@rdecoito

Description

@rdecoito

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.

Issue Description

This isn't actually a complex issue, but I didn't immediately see how to set eslint version 9 in the playground and I wasn't interested in learning, since I already had a reproduction repo set up.

The issue is that when you use the --fix argument with the @typescript-eslint/consistent-type-definitions rule, it will leave a trailing parenthesis if the type it converts was wrapped in parens.

For example, the following code

export type Interface = ({
    [key: string]: unknown;
});

becomes

export interface Interface {
    [key: string]: unknown;
});

triggering a syntax error.

I tried this on the latest version of typescript-eslint, including 8.12.2 and 8.12.3-alpha.1

Reproduction Repository Link

https://github.com/rdecoito/repro-consistent-type-definitions

Repro Steps

Copy-pasted from README in repo:

  1. Clone this repo
  2. Run npm i
  3. Run npm run lint
    • You'll see an error reported that the type defined in src/index.ts should be an interface instead
  4. Run npm run lint -- --fix
    • You'll see a new syntax error reported. Open src/index.ts to see the problem: the rule left behind a parenthesis that it shouldn't have

Versions

package version
typescript-eslint ~8.11.0
TypeScript 5.6.3
ESLint ~9.13.0
node 20.18.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workinglocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: 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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy