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: add "types" field to package.json #24

Merged
merged 2 commits into from Apr 7, 2023

Conversation

dominikg
Copy link
Contributor

@dominikg dominikg commented Mar 9, 2023

So that older versions of typescript without support for exports map are able to resolve types correctly.

see sveltejs/svelte#8362 for an example where it failed

So that older versions of typescript without support for exports map are able to resolve types correctly.
@dominikg
Copy link
Contributor Author

dominikg commented Mar 9, 2023

you may be able to remove typings from package.json, but I left it untouched in case it's used by other tooling i'm not aware of.

@benmccann
Copy link

Removing typings would make sense to me

@jridgewell
Copy link
Owner

Hi all, I haven't merged this yet because I want to redo the way types are discovered according to https://twitter.com/atcb/status/1634653545407610880

@dominikg
Copy link
Contributor Author

hmmm, index.d.cjs is a thing? a recent ts version added .d.cts, but never heard of .d.cjs before.

Is that supported by old versions of typescript too?

And is it resolved/found even if an exports map exists that does not export it?

while specifying "types" in package.json twice is a bit redundant, it allows for wide compatibility without a need to change anything else.

@benmccann
Copy link

That advice seems quite surprising to me. I've also never seen it. If I do a Google search for "index.d.cjs" there's only two results and one is that Tweet

while specifying "types" in package.json twice is a bit redundant, it allows for wide compatibility without a need to change anything else.

I don't understand why you'd specify types and typings. Aren't they the same except types works in all versions and typings just in some? Why not just use types alone?

@dominikg
Copy link
Contributor Author

i meant "types":"..." being duplicated inside and outside of exports.

if you have a top level "types", "typings" is indeed not needed for typescript itself, so can be removed if no other tool needs it. Im not aware of one, but also not familiar with why "typings" exists in the first place so not 100% sure

@benmccann
Copy link

Ah, thanks for clarifying. types and typings are synonymous: https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html#including-declarations-in-your-npm-package

The other way to deal with this if you want to modernize the package would just be to specify "type": "module" and get rid of the UMD distribution. That would cut the package in half and simplify things quite a bit.

@jridgewell
Copy link
Owner

@andrewbranch does your advice hold for earlier TS versions as well? Or does it only work for more recent ones with support for .cjs, .cts, etc?

@andrewbranch
Copy link

  1. .d.cjs was a typo 🤦 It was supposed to be .d.cts
  2. Nothing I suggested will break older versions of TypeScript, but a lot of the content is specific to doing the right thing for --module nodenext.

@benmccann
Copy link

Note that .d.cts only was introduced in TypeScript 4.7 (source) and most users don't use nodenext

It seems safest to me to just replace typings with types

package.json Outdated Show resolved Hide resolved
@jridgewell jridgewell merged commit da81d71 into jridgewell:main Apr 7, 2023
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

4 participants