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

Add type definitions to exports in package.json #21

Merged
merged 2 commits into from
Mar 31, 2023

Conversation

mrdrogdrog
Copy link
Contributor

@mrdrogdrog mrdrogdrog commented Jun 24, 2022

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 😅

src/y-doc-message-transporter.test.ts:11:27 - error TS7016: Could not find a declaration file for module 'y-protocols/awareness'. '[...]/node_modules/y-protocols/dist/awareness.cjs' implicitly has an 'any' type.
  Try `npm i --save-dev @types/y-protocols` if it exists or add a new declaration (.d.ts) file containing `declare module 'y-protocols/awareness';`

@dmonad
Copy link
Member

dmonad commented Jun 26, 2022

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.

@mrdrogdrog
Copy link
Contributor Author

Good evening @dmonad,

thanks for the PRs!

Thanks for the lib 👉 😎 👉

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 🙃 . 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? 🤔

@mrdrogdrog
Copy link
Contributor Author

mrdrogdrog commented Jul 8, 2022

Anything new?

@mrdrogdrog
Copy link
Contributor Author

mrdrogdrog commented Oct 22, 2022

Hey. @dmonad I really need this change. Can you please take a look again? :/

@dmonad
Copy link
Member

dmonad commented Mar 31, 2023

Sorry for the long wait. Will get this into a new release once #27 is ready

@dmonad dmonad merged commit ba21a9c into yjs:master Mar 31, 2023
@mrdrogdrog mrdrogdrog deleted the add-types-in-package-json branch March 31, 2023 18:39
@mrdrogdrog mrdrogdrog restored the add-types-in-package-json branch March 31, 2023 18:39
@mrdrogdrog mrdrogdrog deleted the add-types-in-package-json branch March 31, 2023 18:39
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