-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: [consistent-indexed-object-style] Unsafe autofix with regards to circular references [8.12.1 regression] #10224
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
Comments
Took a cursory look at this. It seems like there is an already an attempt to have this rule not fail if there are circular index signatures, but it doesn't handle the following cases:
type MyCircularType2 = { [P in "foo" | "bar"]: MyCircularType2 };
type Bar = { [k: string]: Foo };
type Foo = string | Bar; I'm guessing that fixing 1) is tractable, but I'm not sure about 2). @kirkwaiblinger I can try to write a PR to fix one or both if you have some pointers? Is https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts#L70-L75 the place to fix? |
It's doubtful that we can handle the second case. |
Yeah, case 1 was for sure an oversight. I simply didn't think of possibly-circular types in #10160. Seems reasonable to check the circularity detection logic you've linked for the tbh Case 2 feels like it could be detectable too if you want to wanted to implement a cycle detection algorithm for the type variables. Questionable how worthwhile this is, perhaps. But, conceptually I'd think we could analyze syntactically:
(note that I'm spitballing; I haven't tried doing something like this and don't know of an example in this repo offhand) |
Following from previous comment, I think that the issue for 1 is that typescript-eslint/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts Lines 146 to 208 in 9c956ee
simply doesn't hit any of the logic in typescript-eslint/packages/eslint-plugin/src/rules/consistent-indexed-object-style.ts Lines 67 to 79 in 9c956ee
So I'd guess that copying/porting/unifying the logic would address point 1. |
Note that the "in operator" here isn't really an "in operator". It's just the syntax that distinguishes a mapped type ( Mentioning this clarification in case it helps make sense of the current code referring to |
Before You File a Bug Report Please Confirm You Have Done The Following...
Playground Link
https://typescript-eslint.io/play/#ts=5.4.3&fileType=.tsx&code=FAUwHgDg9gTgLgAjgTwiBBZZBhAljAYwFcAbAQxgBVV0BeYBBAHwQCMooSQyA7B5hDyIBbViBj8WAbwQBtAAoJcPBAGc4MZQHMAugC5MOfMXJUaCAL4BuYMAD0dhOGjwk5rHkKkK1NACYEegdGAXZObj5gxhYhUXF7R2iEACUQAlgAEwAedU0eLQAaQ08THxo-AD4rIA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6MgeyeUuX0Ra1mAE0QAPRMNocARgCtEZOn0JJ0URNGgdokcGAC%2BIA0A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false
Repro Code
ESLint Config
tsconfig
Expected Result
This should not be a lint error. The autofix produces code that does not typecheck:
2456: Type alias 'MyCircularType' circularly references itself. 2:13 - 2:27
This appears to be intended behavior, according to microsoft/TypeScript#35164
Actual Result
Autofixed into code that doesn't typecheck:
Additional Info
Probably caused by #10160.
The text was updated successfully, but these errors were encountered: