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

Autocomplete is not reliable with subpath exports #58777

Closed
jansedlon opened this issue Jun 5, 2024 · 3 comments
Closed

Autocomplete is not reliable with subpath exports #58777

jansedlon opened this issue Jun 5, 2024 · 3 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@jansedlon
Copy link

jansedlon commented Jun 5, 2024

πŸ”Ž Search Terms

  • subpath autocomplete
  • exports autocomplete
  • subpath

πŸ•— Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about Export maps aren't respected

⏯ Playground Link

https://github.com/jansedlon/ts-monorepo-issue/tree/main

πŸ’» Code

{
  "exports": {
      "./package.json": "./package.json",
      "./zod/base": {
        "types": "./dist/src/zod/base.d.ts",
        "import": "./dist/src/zod/base.js"
      },
      "./zod": {
        "types": "./dist/src/zod/index.d.ts",
        "import": "./dist/src/zod/index.js"
      }
    },
}
import { index } from "@ts-monorepo/validation/zod";
//        One level depth is autocompleted    ^
// This works ONLY if there's one level depth export in package.json

import { EmailSchema } from "@ts-monorepo/validation/zod/base.ts";
//                      No autocomplete beyond this ^
// If there's no `./zod` export in `exports`, not even `zod` path is autocompleted

πŸ™ Actual behavior

As you can see in the example, my base tsconfig.json has resolvePackageJsonExports set to true.
My packages have exports field in package.json to export a bunch of things. There are actually two issues.

  1. There's no autocomplete beyond one level depth of exports.
  2. In my production application, there's like 90% chance that any given thing exported from my packages are not suggested for imports. I have to import it at least once for it to appear later. And even that is forgotten after some time.

πŸ™‚ Expected behavior

It should autocomplete all given paths defined in exports field.
It should suggest all exported things from a package

Additional information about the issue

The second issue is tricky because it doesn't happen in this small reproduction.
My app have around 100k LOC and almost all exported things in my packages cannot be autoimported because typescript somehow doesn't know about them.

If i import them once, they can be autoimported later on somwhere else. However after some time (or after vscode reload), it's forgotten again.

@jansedlon
Copy link
Author

Seems like "typescript.preferences.includePackageJsonAutoImports": "on" option in vscode fixed it but I'm not sure what's the performance penalty for this? I already struggle with autocomplete performance.

@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Jun 6, 2024

This is the expected behavior with that flag off, and turning that flag on is the correct thing to do if that's what you want to happen

@RyanCavanaugh RyanCavanaugh added the Working as Intended The behavior described is the intended behavior; this is not a bug label Jun 6, 2024
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Working as Intended" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

3 participants