fix: imported subpaths types correctly #569
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: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:
GitHub - tkafka/lowdb-node-fail: A sample for lowdb issue: https://github.com/typicode/lowdb/issues/554
GitHub - minimusubi/cannot-find-lowdb
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.