-
Notifications
You must be signed in to change notification settings - Fork 12.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
Mechanism for package authors to give auto-import hints #53037
Comments
Oh yes 🙏 this would be super awesome. In a similar vein... some consumers prefer namespace-based imports so it would be cool to have that configurable from the consuming side of things as well. |
Is there any reason that you prefer the subpath export? |
Hm, I didn't exactly have subpath exports/imports in mind. Just that in some codebases // pre
useStat/*cursor*/
// post
import * as React from 'react'
React.useState/*cursor*/ |
Wow, I was really confused for a moment there about how this ended up on the typescript repo. @DanielRosenwasser Importing from root exports increases overhead in testing and build processes due to increased IO churn and tree-shaking. We actually have a linting rule to prevent importing from several root packages, like So vscode's auto-import always grabbing the root increases development time, since it immediately gets flagged by eslint. |
I sort of wonder if the package itself is the right place for this information. Related, it looks like someone's already made a VS Code plugin for this exact situation. Does #49578 fix this in your project? I'm not sure what the matching rules are but it seems like you could block imports from exactly |
@RyanCavanaugh ohh, that might indeed solve it. I'll take a look today Edit: Unfortunately, this just removes MUI from the auto-import entirely, it doesn't make the deeper file available. Same happens for our own internal libs with subpath exports. The issue seems to be that vscode isn't even seeing those other options. Material doesn't use subpath exports, they just rely on node-resolution to hit the deeper pathways, so it would seem vscode isn't traversing the exports when deciding what files to offer. My own utils library does use subpath exports, however, and still has the same result. Like if I type |
I figured it out! I can actually solve for this, by defining a
This gets vscode to properly recommend the subpath export instead of the root export. Problem solved! |
I'm not sure how that would solve the issue (it doesn't for my case) |
Apologies if this exists and I just couldn't find documentation on it. We have several in-house npm packages to offer common functionality across our codebases. Each of these packages defines subpath
exports
entries to directly target individual functions and components, in addition to getting everything from the root entry. To use an example with MUI, you can do either of these:or
The problem is, the auto-import completion rarely even lists the later, just the former, or sometimes, when it does go deeper, it tries to import the direct file (eg,
@mui/material/node/Grid/Grid.js
) instead of using the subpath export.It would be very helpful if I, as a package author, could give weight to the exports so that I can tell vscode "this is actually the better path to use for suggesting this export."
The text was updated successfully, but these errors were encountered: