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

generate .d.ts file on publish #1

Merged
merged 1 commit into from
Nov 1, 2024
Merged

Conversation

Rich-Harris
Copy link
Contributor

Hello! Thank you for this library — we're investigating using it on https://svelte.dev/playground.

As you can see on the PR, we needed to add a declare module declaration in order to use it with type safety, and the declaration files are quite large (and prone to get out of date). Since you've already gone to the trouble of annotating everything with JSDoc comments, I wondered if you'd be open to a small prepublishOnly script that generates .d.ts files automatically?

It does introduce a devDependency on typescript, which I recognise isn't everyone's cup of tea. But it allows users of this library to get autocomplete and inline documentation and type safety, and also helps to ensure that this package remains bug-free (e.g. you'll notice TypeScript caught a small discrepancy in the type field).

Thank you for your consideration!

@highercomve
Copy link
Owner

Thanks for the PR

Sounds good, but I need to publish the module again to npm to push the types. I'm not used to how the types work with npm.

Again thanks

@highercomve highercomve merged commit 7a787b3 into highercomve:main Nov 1, 2024
@Rich-Harris Rich-Harris deleted the dts branch November 1, 2024 22:54
@Rich-Harris
Copy link
Contributor Author

Thank you! All that needs to happen to make it work is npm publish (after bumping the version in package.json and running npm install to install TypeScript locally) — the script will generate the types/index.d.ts file automatically on publish, and from there it will be included in the package on npm

@highercomve
Copy link
Owner

@Rich-Harris Done, the new version has been published (0.0.3)

Again thanks for the PR

@paoloricciuti
Copy link

@Rich-Harris Done, the new version has been published (0.0.3)

Again thanks for the PR

Hi, unfortunately it doesn't seems the new version published the .d.ts files. Do you happen to have a .gitignore or .npmignorelocally that is not checked out in the repo? After you run publish locally do you have atypes/index.d.ts` file locally?

@Rich-Harris
Copy link
Contributor Author

Ah, whoops, this is my bad — I didn't add a "files" entry to the package.json thinking that it would continue to publish everything in the package, but I also added types to .gitignore so that they wouldn't clutter up the repo. Will open a PR. Sorry!

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.

3 participants