-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[consistent-type-imports] prefer inline type import syntax #4338
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
As I mentioned in my comment here: #3950 (comment) EG this code: import type { cType } from './c';
import { aValue } from './a';
import type { bType } from './a'; Or this code: import type { cType } from './c';
import { aValue, type bType } from './a'; Would never error in this rule - regardless of config - because all the types are imported via type imports. However, I do think that this lint rule's fixer could very much be concerned with fixing to "condensed" imports when configured to do so.
(option names are up to whomever implements - the above are just an example) Fixed output example: import type { dType1 } from './d';
import { dType2 } from './d';
import { cType } from './c';
import { aValue, bType } from './a';
// `separate-type-imports` fix to
import type { dType1, dType2 } from './d';
import type { cType } from './c';
import type { bType } from './a';
import { aValue } from './a';
// `inline-type-imports` fix to
import type { dType1, dType2 } from './d';
import { type cType } from './c';
import { aValue, type bType } from './a';
// `mixed` fix to
import type { dType1, dType2 } from './d';
import type { cType } from './c';
import { aValue, type bType } from './a'; |
Yes, totally agree with having this in Regarding the fixer, like you said, it could be a little complicated, so I might not pursue it here. But I want to bring to your attention, the Basically import { type cType } from './c'; will cause a Typescript compilation error when |
I don't believe we should be maintaining our extension rule, I would like to remove our extension rule in the next major, so I don't hugely want us to add more functionality into it for now. |
@bradzacher that's a very fair point! I totally forgot about this base rule. I will close this issue now. |
I'll leave this open as a tracking issue in case someone wants to implement the changes to the fixer. |
You can now achieve this with |
I believe this is still something we want in this repo even with the additions to the canonical? If so, I've started working on a fix. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Is there any way to disable the fixer for consistent-type-imports in the meantime? The fixer just ends up causing hundreds of new issues when used in conjunction with import/no-duplicates. |
@blingerson Could you detail some of the issues you found and perhaps we can fix them? Even better in a new issue! |
import-js/eslint-plugin-import#2469 has been merged but not yet released. |
@bradzacher Amazing! Just to note, we have 2/3 left to get proper inline imports. This PR is next I believe. |
Description
I would like to propose an extension to the existing
consistent-type-imports
rule. This is linked to the work done in #4237I think it would be beneficial for people who are interested in adopting the new inline type import syntax introduced in Typescript 4.5. We can introduce a flag, for example
preferInlineTypeImports?: boolean
.Like @bradzacher mentioned, it's tricky to do a fixer, so we don't need it for now, but at least a way to warn people about violation would be great.
Fail
Pass
Let me know what you think about this. If you give me a green light, I think if I can try working on this feature.
The text was updated successfully, but these errors were encountered: