Closed mrdrogdrog closed 1 year ago
Hi @mrdrogdrog,
thanks for the PRs! I didn't know that you can add a types
field to named module exports.
Usually - or so I thought - typescript checks whether there is a .d.ts
file next to the imported .js
/.cjs
file. This is why I currently export a module declaration for each exported file (there are definitely duplicates in dist/
and root /
).
Can you please verify that this works by applying the changes from this PR to the package.json
file in node_modules/y-protocols/package.json
?
Could you also please tell me what kind of TS setup you are using (or TS version)? This is more for my own sanity. It might even motivate me to maintain the types
field in the other packages.
Good evening @dmonad,
thanks for the PRs!
Thanks for the lib :point_right: :sunglasses: :point_right:
I didn't know that you can add a types field to named module exports.
Neither did I until one of my projects exploded and I read the docs) for named exports.
Usually - or so I thought - typescript checks whether there is a .d.ts file next to the imported .js/.cjs file. This is why I currently export a module declaration for each exported file.
That's true usually typescript do so and it works fine. But the exploded project uses ts-jest which explictly wants to import the cjs version of the lib even though my project is a module. sigh anyway. ts-jest
claims that the defintions are missing. So I checked the node_modules directory and......
(there are definitely duplicates in dist/ and root /)
.... found out that this isn't true :upside_down_face: . There are no declaration files in the dist folder. Or at least not in the package that I downloaded from npm. I guessed it was a mistake so I investigated this problem. Instead of fixing the build script and duplicate the .d.ts files I found this much more elegant solution.
Can you please verify that this works by applying the changes from this PR to the package.json file in node_modules/y-protocols/package.json?
It works. With this patch ts-jest found the declarations and did its job.
Could you also please tell me what kind of TS setup you are using (or TS version)? This is more for my own sanity. It might even motivate me to maintain the types field in the other packages.
I use the latest typescript version 4.7.4. Or what do you mean with setup? :thinking:
Anything new?
Hey. @dmonad I really need this change. Can you please take a look again? :/
Sorry for the long wait. Will get this into a new release once #27 is ready
The package doesn't explicitly export the generated typescript definitions. This PR adds the type definition files to the exports in the package.json
I hope to solve this problem with that :sweat_smile: