-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
import/no-cycle should not trigger for TypeScript type imports #1453
Comments
Flow has import type; TS does not - I’m not sure how we could statically know it’s a type on the import side, especially with d.ts files being a thing. |
The tsc and babel both make best guesses about whether an import is "type only" and remove the import if it is. There is likely a high reliability of detecting it given they feel comfortable enough to remove imports. Unclear whether it's analyzable in a performant way tho |
If the ast node has that info on it then it seems possible to ignore it - a PR would be great. |
My understanding is it's not the import nodes that have it, there is some amount of scope tracking to test it. I'm not qualified to write this but if anyone is interested in where the babel logic is: https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-typescript/src/index.js#L382 |
As of TypeScript 3.8, |
same issue, has any solution? |
nope, nobody's sent a PR afaict. |
Hi, using |
do you have any tips/directions for someone to begin work on a PR? |
For eslint plugins, I'd start by making as many test cases as you can manage, and then you can start debugging what node types you'd need to work with to fix them. |
This would be a great feature! Would like to add that typescript interfaces should also be safe to exclude from this rule since they will be removed when transpiling to js. As a side not, the rule also seems to trigger on a file-by-file basis rather than on an import-by-import basis. In our code-base we have a "Models" directory with data models, often linking to each other. An index.ts includes all models and exports them together.
but the first code style will trigger lots of no-cycle errors most of which can be removed by using the second more verbose syntax. |
Just bumping since this is fairly annoying. |
I can confirm, that using syntax |
@Sytten PRs are welcome. |
With Typescript's new |
I have some files in my codebase which exports types and also enums. Once I use |
|
@RebeccaStevens In case of a circular dependency, as enums are compiled to values in TS, it's fair that the rule applies. So enums should be treated with the same regards as any other imported value :) |
close in favor of above |
Repro
Actual Result
There is the store (imports reducers), reducers (imports actions), and actions (imports store type) in application.
import/no-cycle
rule alerts about cycle dependency, but only type information are cycled and it will be skipped at runtimeRelated
#1343
typescript-eslint/typescript-eslint#843
The text was updated successfully, but these errors were encountered: