Skip to content

Fix type import errors due to usage of "exports" in package.json#2569

Merged
josdejong merged 1 commit into
josdejong:developfrom
goodproblems:types/fix-package.json-types
May 24, 2022
Merged

Fix type import errors due to usage of "exports" in package.json#2569
josdejong merged 1 commit into
josdejong:developfrom
goodproblems:types/fix-package.json-types

Conversation

@mattvague
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

I believe this addresses #2506 as well

@josdejong
Copy link
Copy Markdown
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.

2 participants