-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Allow ambient module names to be filtered out of auto-imports or something #55092
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
This comment was marked as off-topic.
This comment was marked as off-topic.
We discussed adding an |
Ideally these affordances are given to libraries not just consumers. Libraries can have way more impact than having to teach everybody about custom VSCode settings. Especially since paths may change between versions. In React, we have I tried |
Wanted to add here that having the ability to exclude auto imports by module name would be a huge help for setups using tsconfig paths or Specifically, it would (hopefully) allow import suggestions across packages in a repo like this without also suggesting imports from the package's primary entrypoint, which is a barrel file and should be avoided internally. I've struggled against this one for a year or so. Any possible solution would be a huge DX improvement! |
@ssalbdivad / @eps1lon interesting feedback, thanks. If I'm understanding it right, it sounds like you have sort of opposite use cases, which makes a good case for some kind of configuration on either end.
Why isn't a file exclusion of |
There’s a lot more discussion of @ssalbdivad’s issue in #51418, and we were able to figure out a pretty good workaround and some other potential future improvements there. In short, David wanted to exclude The trick was that David’s That said, I still think that’s a good example of how filtering module specifiers would pair well with something like |
The Also just to clarify, the purpose of the setup I'm using (similar to those in @colinhacks recent post) is to have types and runtime imports resolve to |
Would it be possible to also take into consideration excluding a modules exported functions? My specific case is that I have a wrapper on the useImmer library for react which we use exclusively instead of Reacts useState. Therefore to simplify the dx we export this wrapper as useState. We always have two suggestions and the one from react will always be imported by the auto-import feature. Would it be possible to exclude the original useState from @types/react/index.d.ts but keep all the other imports like useEffect etc. |
Suggestion
🔍 Search Terms
autoImportFileExcludePatterns, exclude auto import suggestions
✅ Viability Checklist
My suggestion meets these guidelines:
⭐ Suggestion
The option
autoImportFileExcludePatterns
currently works on the package/module (?) level. I can prevent a whole package from being suggested in auto-imports, but I can't exclude only some of the imports in certain subdirectories of that package. This was already mentioned as a caveat in the original implementation of the option (#49578 (comment)).📃 Motivating Example
As in the comment mentioned above, my issue also comes from
date-fns
, but for a slightly different reason. The package has alocale
module that includes exports for many different two-letter country codes. Those names also happen to conflict with variable names quite often. When typing one of the country codes, I get tons of suggestions fromdate-fns
which appear before the one I actually want:It's a minor annoyance, but I'd like to exclude those suggestions.
💻 Use Cases
Currently, I can add
"**/node_modules/date-fns"
or"date-fns"
to theautoImportFileExcludePatterns
option, which completely removesdate-fns
suggestions. But then I also lose the suggestions I actually want from the library.I tried adding
"date-fns/locale"
,"date-fns/locale/**"
,"date-fns/locale/*.*"
, but none of those work and result in no suggestions being excluded at all.The text was updated successfully, but these errors were encountered: