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

fix: imported subpaths types correctly #569

Merged
merged 2 commits into from
Apr 28, 2023
Merged

fix: imported subpaths types correctly #569

merged 2 commits into from
Apr 28, 2023

Conversation

nulkode
Copy link
Contributor

@nulkode nulkode commented Apr 23, 2023

Problem

The problem itself is that in node module resolution, typescript can't import the subpaths' modules or the modules' types. The problem was not the modules but the types, as this works perfectly in Javascript without types. Investigating I found that there's no way to export many type files to include every type file for every subpath. I tried this at first:

"exports": {
    ".": {
      "import": "./lib/index.js",
      "types": "./lib/index.d.ts"
    },
    "./node": {
      "import": "./lib/node.js",
      "types": "./lib/node.d.ts"
    },
    "./browser": {
      "import": "./lib/browser.js",
      "types": "./lib/browser.d.ts"
}

But the types weren't being exported. I tried to find the solution in the typescript documentation, but there's no article regarding subpaths, so I think there's no native support for subpath types.

Solution

Finally, I found this repository that was addressing this particular case. It uses typesVersions to include many types for the other subpaths. It is a bit messy, but it's the only solution I had found for this case.

I ran this solution on these minimum reproduction repositories from #554:

I also run this on my repository of my issue #568 and it solves it too.

So this solution gives compatibility for the node module resolution with typescript.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants