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 types with dts-buddy #658

Closed
wants to merge 21 commits into from
Closed

generate types with dts-buddy #658

wants to merge 21 commits into from

Conversation

Rich-Harris
Copy link
Member

  • types for exported functions are declared on the functions themselves, rather than in the .d.ts file
  • a types/index.d.ts file is generated with an accompanying types/index.d.ts.map, meaning cmd-click takes you to the implementation

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

"import": "./src/index.js"
},
"./package.json": "./package.json"
},
"scripts": {
"dev": "pnpm typecheck --watch",
"build": "pnpm typecheck",
"typecheck": "tsc --noEmit --allowJs --checkJs"
"typecheck": "node scripts/generate-dts.js"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the script would have to be called something like build:types or generate:types to make it more clear that it has output. check suggests it doesn't change.

When exactly would this have to be called during release, how do you ensure that it's output in /types stays in sync with changes to types in /src

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

elsewhere i'm using prepublishOnly for this

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that does not ensure it stays in sync. You would have to call it in prepare (similar to how svelte called build in prepare). and even that isn't enough because types can still change and you end up with revisions where they are out of sync.

@dominikg
Copy link
Member

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
Copy link
Member Author

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 dominikg marked this pull request as draft May 25, 2023 07:21
@dominikg
Copy link
Member

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

Base automatically changed from refactor/ts2jsdoc-step2 to main May 25, 2023 14:07
@dominikg
Copy link
Member

closing in favor of #751

@dominikg dominikg closed this Sep 16, 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.

3 participants