Fix type import errors due to usage of "exports" in package.json #2569
+3
−0
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.
Summary
Add "types" field to "exports" to fix type imports
Description
I was having trouble getting the mathjs typescript types working in my app:
I previously worked around this by adding this to my tsconfig.json
But that was a bit hacky and started causing other problems, so I decided to figure out what was going on. Seems that the "types" field in package.json is not respected when using "exports". Luckily as of typescript 4.7, "exports" itself supports "types" fields for each declaration as well (see here).
Now, my app is using
type: "module"
so I'm not sure if this will work with the CJS import as well but I assume it will (if someone could check that would be great).After adding this fix my types now work with no hacks 💥