Skip to content
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

Add user preference for preferring type-only auto imports #56090

Merged
merged 2 commits into from Oct 20, 2023

Conversation

andrewbranch
Copy link
Member

Closes #55675

This makes the auto-imports behavior of verbatimModuleSyntax available as an editor preference, independent of compiler options. Stylistic preference for type-only imports has been a popular demand since the syntax was introduced, and compiler options which may or may not be appropriate for a user’s actual compilation have long been adopted for their side effects on auto-import behavior. This setting allows users to separate their stylistic preference from picking the right compiler options for their actual use case.

Copy link
Member

@jakebailey jakebailey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me, though I can't help but feel like we're going in circles a bit 😅

I guess anyone who actually wants to enforce this needs verbatimModuleSyntax and/or the two ts-eslint rules, and this at least helps the editor do the right thing, more or less exactly like my proposal for how we should better handle import sorting.

Comment on lines -1621 to +1628
compilerOptions.verbatimModuleSyntax &&
(compilerOptions.verbatimModuleSyntax || preferences.preferTypeOnlyAutoImports) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this use shouldUseTypeOnly somehow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern with verbatimModuleSyntax is slightly different, so I don’t think so

@jakebailey
Copy link
Member

(of course note that the PR is failing, some missing baselines)

@typescript-bot
Copy link
Collaborator

Looks like you're introducing a change to the public API surface area. If this includes breaking changes, please document them on our wiki's API Breaking Changes page.

Also, please make sure @DanielRosenwasser and @RyanCavanaugh are aware of the changes, just as a heads up.

@andrewbranch andrewbranch merged commit aef4e46 into main Oct 20, 2023
19 checks passed
@andrewbranch andrewbranch deleted the feature/55675 branch October 20, 2023 21:52
@johnnyreilly
Copy link

This is amazing!! I will be updating my blog post on the topic: https://johnnyreilly.com/typescript-5-importsnotusedasvalues-error-eslint-consistent-type-imports

I'll confess to being possibly unhealthily interested in being exact in the type (ha!) of my imports. Every time a type import is used, an angel gets their wings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support a user preference for preferring the type keyword in auto-imports
5 participants