Skip to content

Missing subfolder path completions with wildcard typesVersions #47952

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

Closed
kim3er opened this issue Feb 18, 2022 · 10 comments · Fixed by #49154
Closed

Missing subfolder path completions with wildcard typesVersions #47952

kim3er opened this issue Feb 18, 2022 · 10 comments · Fixed by #49154
Assignees
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone

Comments

@kim3er
Copy link

kim3er commented Feb 18, 2022

Bug Report

Sub folders of a folder listed in typeVersions, do not resolve in VS Code's autocomplete. I originally believed the issue to be related to Support for NodeJS 12.7+ package exports.

🔎 Search Terms

typeVersions
autocomplete

🕗 Version & Regression Information

This is using Visual Studio Code 1.64.2 and TypeScript 4.5.5. I believe this bug to not be a revision, and is not resolved in TypeScript 4.7.0.

⏯ Playground Link

Code required relationship between two projects, so used Github instead.

Github repo

💻 Code

We have an internal package, written in TS, transpiled to a sub folder called 'dest'. The package.json of the package looks like:

{
  ...
  "type": "module",
  "exports": {
    "./*": "./dest/*"
  },
  "typesVersions": {
    "*": {
      "*": [
        "dest/*"
      ]
    }
  },
  ...
}

We're able to consume the package in our projects, like this:

import { something } from 'test-package/something'; // Actual file './dest/something.js'

This works. Our code is transpiled correctly. We get autocomplete on the import path, and typing on the imported whatever, within VS Code.

Until, we attempt to access a sub folder within the 'dest' folder. Within a subfolder, like:

import { somethingElse } from 'test-package/sub-folder/something-else'; // Actual file './js/sub-folder/something-else.js'

In this instance, we get everything from above, except autocomplete on the import path. The file still resolves, and we get typing. Our build script still runs, the files is just invisible.

This is using Visual Studio Code 1.64.2 and TypeScript 4.5.5. Both project and package have the following tsconfig.json:

{
  ...
    "target": "ES2016",
    "module": "ESNext",
  ...
}

🙁 Actual behavior

Autocomplete does not resolve the scripts with the sub folder.

Demo

🙂 Expected behavior

Autocomplete should resolve the scripts within a sub folder.

@jasonwilliams
Copy link

jasonwilliams commented Feb 18, 2022

I was about to raise this too. I was following https://2ality.com/2021/07/simple-monorepos.html#a-better-solution%3A-npm-workspaces-and-typescript-project-references

I needed to have paths in a library instead of just one default export.

@andrewbranch I know you worked on this feature, is this a bug? It looks like the resolution works but just not on auto complete? Long term we would use TypeScript's ESM support when that's released, but in the meantime we need to use typeVersions.

Here is another example:

autocomplete.mp4

Here is a test case repository (shown in the video).
https://github.com/jasonwilliams/subpath-testcase

@kim3er
Copy link
Author

kim3er commented Feb 18, 2022

Hey @jasonwilliams, that blog was also my starting point! 😁

@andrewbranch andrewbranch changed the title Sub folder when used in conjunction with typeVersions Missing subfolder path completions with wildcard typesVersions Feb 18, 2022
@andrewbranch
Copy link
Member

@jasonwilliams your case is a separate issue. Does it work after there is already one import of projecta elsewhere in projectb? If not, that’s another separate issue.

@jasonwilliams
Copy link

@jasonwilliams your case is a separate issue. Does it work after there is already one import of projecta elsewhere in projectb? If not, that’s another separate issue.

no it doesn't. And in the video you can see I have the top line, the second line still doesn't work.
But even if i import from another file in project B, it still won't auto complete elsewhere

@andrewbranch
Copy link
Member

Answering my own question, that does work.

image

@andrewbranch
Copy link
Member

Since typesVersions and exports are structured quite similarly, fixing @jasonwilliams’ issue would probably be a pretty straightforward parallel addition to the changes added here: https://github.com/microsoft/TypeScript/pull/47092/files#diff-fad6af6557c1406192e30af30e0113a5eb327d60f9e2588bdce6667d619ebd04

@jasonwilliams
Copy link

jasonwilliams commented Feb 18, 2022

Hey @andrewbranch could you explain how both of our casing are different when we’re working from the same tutorial. It seems the issue is typeversions and using a wildcard which seems to be what we’re both doing.

@andrewbranch
Copy link
Member

The way auto imports work and path completions work are just super different. Two different language features with completely different code paths.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Feb 23, 2022
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 4.7.0 milestone Feb 23, 2022
@jasonwilliams
Copy link

jasonwilliams commented Mar 22, 2022

I've just tested this again with the 4.7.0-dev.20220322 version and it still doesn't work. (auto complete doesn't work but the module is definitely there).

I have set VSCode to use the workspace version and it made no difference. Is this expected @andrewbranch ?

If i understand #47836 (comment) correctly we no longer need the "typeversions" hack as the completions are now coming from the exports mapping. Although that didn't make much different.

UPDATE

I've removed the asterisks in the pattern in exports (prev "./submodule/*" now "./submodule") and now the subpath auto completes. But the initial import doesn't autocomplete inside the import { | } block.

I can trigger auto complete here:
import { thing } from 'project/|' but ive already typed out most of it by this point

UPDATE 2

I've just switched from Node12 to NodeNext and its now working as expected. (not sure the difference between the 2).

@TheMrZZ
Copy link

TheMrZZ commented Apr 12, 2022

Using Typescript 3.7 beta, I get the exact same issue with the exports field. I didn't find another issue specifically for this, is there already one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fix Available A PR has been opened for this issue Needs Investigation This issue needs a team member to investigate its status. Rescheduled This issue was previously scheduled to an earlier milestone
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants