sveltejs / vite-plugin-svelte

Svelte plugin for http://vitejs.dev/
MIT License
844 stars 103 forks source link

generate types with dts-buddy #658

Closed Rich-Harris closed 1 year ago

Rich-Harris commented 1 year ago

Unfortunately couldn't use the CLI for this because the entry point is a .d.ts file rather than a .js file, so this happens via a new scripts/generate-dts.js module

dominikg commented 1 year ago

This basically duplicates src/public.d.ts into types/index.d.ts with the addition of a sourcemap. Is there a way to get the same result without the sourcemap and all these moving parts? v-p-s types are tiny, if all it takes is changing src/index.d.ts to declare the module in place instead of using declare function i'm fine with that.

Rich-Harris commented 1 year ago

Is there a way to get the same result without the sourcemap and all these moving parts?

Unfortunately not, unless you want to create a sourcemap by hand. Though I think re-exporting from index.js (so the function types are declared inline rather than with declare function) will work in either case.

It does add moving parts and the benefit is more modest in this case since there's really just one giant .d.ts file in src — no pressure to merge this PR, I was largely just curious about what it would look like (and I found a couple of dts-buddy bugs along the way, so it was worthwhile for me). Having cmd-click work properly is nice, but might not be worth the trade-off. Your call

dominikg commented 1 year ago

changed to draft for now until we figure out how to integrate it properly

dominikg commented 1 year ago

closing in favor of https://github.com/sveltejs/vite-plugin-svelte/pull/751