Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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
rdecoito opened this issue Oct 29, 2024 · 1 comment · Fixed by #10235
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@rdecoito
Copy link

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
@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Oct 29, 2024

playground link.

(Please do try it next time! it really is easy! 😊 I just copied your code in and added consistent-type-definitions to the rules object).

@kirkwaiblinger kirkwaiblinger 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 Oct 29, 2024
@bradzacher bradzacher added the package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin label Oct 29, 2024
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Nov 12, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 12, 2024
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 locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
3 participants