feat(dts): add cjsReexport option to eliminate dual module type hazard#856
Open
mandarini wants to merge 2 commits intorolldown:mainfrom
Open
feat(dts): add cjsReexport option to eliminate dual module type hazard#856mandarini wants to merge 2 commits intorolldown:mainfrom
mandarini wants to merge 2 commits intorolldown:mainfrom
Conversation
✅ Deploy Preview for tsdown-main ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
tsdown
create-tsdown
@tsdown/css
@tsdown/exe
tsdown-migrate
commit: |
bae4d23 to
29cbf78
Compare
Member
|
Thanks for the PR! The use case is valid — the dual module type hazard is a real pain point. However, the current implementation writes the Could you refactor the approach to use a Rolldown plugin? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When building dual ESM+CJS formats, tsdown runs two separate TypeScript compilation passes, one producing
.d.mts, one producing an independent.d.cts. Because TypeScript's class identity is nominal, these two declarations are treated as unrelated types by consumers that mix CJS and ESM resolution paths (e.g. NestJS apps importing a package that also has ESM-only internal dependencies). This producesTS2352"neither type sufficiently overlaps" when casting between types derived from the same class.This PR adds a
dts.cjsReexport: booleanoption (opt-in, defaultfalse). When enabled in a dual-format build, tsdown skips the second compilation pass and writes a.d.ctsstub that re-exports from the corresponding.d.mts:Both CJS and ESM consumers now resolve to the same declaration, eliminating the dual module type hazard entirely.
Additional info
This PR contains AI-generated code, but I have carefully reviewed it myself. We use
tsdownon https://github.com/supabase/supabase-js and it would be nice if we could use this.