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 type import errors due to usage of "exports" in package.json #2569

Merged

Conversation

mattvague
Copy link
Contributor

@mattvague mattvague commented May 21, 2022

Summary

Add "types" field to "exports" to fix type imports

Description

I was having trouble getting the mathjs typescript types working in my app:

image

I previously worked around this by adding this to my tsconfig.json

image

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).

image

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 💥

image

@mattvague mattvague changed the title Add "types" field to "exports" to fix type imports Fix type import errors due to usage of "exports" in package.json May 21, 2022
@mattvague
Copy link
Contributor Author

I believe this addresses #2506 as well

@josdejong
Copy link
Owner

Wow, that makes a lot of sense indeed. Thanks for figuring this out!

@josdejong josdejong merged commit 08c6a1e into josdejong:develop May 24, 2022
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.

None yet

2 participants