Closed
Description
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:
- Clone this repo
- Run
npm i
- Run
npm run lint
- You'll see an error reported that the type defined in src/index.ts should be an interface instead
- 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 |