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

Bundled type definitions for bundled dependencies? #1050

Open
donmccurdy opened this issue Jun 20, 2023 · 5 comments
Open

Bundled type definitions for bundled dependencies? #1050

donmccurdy opened this issue Jun 20, 2023 · 5 comments

Comments

@donmccurdy
Copy link
Contributor

donmccurdy commented Jun 20, 2023

Context: As documented in #454 and How Microbundle decides which dependencies to bundle, one recommended way to bundle dependencies is to put the dependency in devDependencies rather than dependencies.

Problem: my-bundled-dependency is bundled into my-parent-library, and affects its exported type definitions. Recently a downstream user of my package reported an issue that surprised me – while the JavaScript is bundled as expected, the type definitions are not bundled, and contain an import from my-bundled-dependency. This causes builds to fail for users of my-parent-library if they've enabled TypeScript's skipLibCheck: false. If this is unexpected and a simple repro example would be helpful, I'm happy to create that.

Alternatives: Should the type definitions also be bundled by Microbundle? By TypeScript? Am I perhaps making a mistake by using a bundled dependency in my exported TypeScript API? I'm inclined to the idea that this is something TypeScript, not Microbundle, should ideally handle. But they've historically been pretty unenthusiastic about such requests.

Related:

@rschristian
Copy link
Collaborator

Indeed, and it will also cause issues if my-bundled-dependency's types are exposed in some way, as at best, they'll just be an any.

Its tough, as we don't really want to go too far off the TS reservation and have to deal with bundling .d.ts files ourselves, but it doesn't look like TS will address it either.

@donmccurdy
Copy link
Contributor Author

Understood, and thanks for confirming! In this case I can remove my-bundled-dependency from the exported API of my-parent-library, working around the issue. Glad to defer to you on whether to close or continue tracking this ticket.

@rschristian
Copy link
Collaborator

Alternatively, you may be able to post-build copy the .d.ts files from the modules that you have inlined into your own dist/ folder or whatever. I get it's far from ideal, but could work.

We'll definitely keep this open, I don't think we have any other issues tracking it and it's a very valid pain point.

@ScottAwesome
Copy link

ScottAwesome commented Jun 24, 2023

Have a look at API Extractor which can bundle types (uses rollup under the hood). Its maintained by Microsoft. I've used in the past. It works pretty well. Its not perfect, but it is really smooth most of the time.

I wish all library maintainers used it to package up their types with their outputs. It does a really good job of making sure your types match what you're exporting as a consumable API

@donmccurdy
Copy link
Contributor Author

Thanks @ScottAwesome! I've used API Extractor elsewhere, though using it to bundle external type definitions hadn't occurred to me. It's been an effort to set up and run in the past — not the "zero configuration" appeal of Microbundle — so I don't feel it's something I can include in my builds as a library maintainer. I deeply wish TypeScript would reconsider their position on bundling, but that's another matter.

I am keeping an eye on dts-buddy as well, though it's still experimental at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants