Skip to content

fix: detect and internalize types in more cases#175

Open
kalvenschraut wants to merge 9 commits intosxzz:mainfrom
RTVision:fix/type-only-import-detection
Open

fix: detect and internalize types in more cases#175
kalvenschraut wants to merge 9 commits intosxzz:mainfrom
RTVision:fix/type-only-import-detection

Conversation

@kalvenschraut
Copy link
Copy Markdown

  • This PR contains AI-generated code, but I have carefully reviewed it myself. Otherwise, my PR may be closed.
    • I understand that my PR is more likely to be rejected or requested for changes if it contains AI-generated code that I do not fully understand.

Description

Try handle namespace type imports and make sure they are internalized along with other types that are used from internal .d.ts files that do not have export { } in them meaning they are considered imported per microsoft/TypeScript#57764

Linked Issues

tries to address issues I opened on tsdown's repo
rolldown/tsdown#743
rolldown/tsdown#744

Additional context

As I indicated I had AI look into this with me overseeing and guiding it. Going mark this as an initial draft to hopefully get feedback while I review and make any changes I see on review.

@kalvenschraut kalvenschraut marked this pull request as draft February 1, 2026 06:41
@kalvenschraut
Copy link
Copy Markdown
Author

kalvenschraut commented Feb 1, 2026

I did look over everything and nothing glaring that i see but I don't have a lot of context to know if it is the right fixes or now hoping to get some feedback. My original issues actually stemmed from me having dependencies as dev dependencies in a monorepo package that should have really been peer dependencies, but since I use catalog pnpm deps to make sure everything stays in sync and dont use the package outside of the monorepo workspace I never ran into issues. It seems like tsdown/rolldown-plugin-dts will internalize types so I figured this was the correct approach in that scenario

@kalvenschraut kalvenschraut marked this pull request as ready for review February 1, 2026 06:45
Copy link
Copy Markdown
Owner

@sxzz sxzz left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this — the export = namespace pattern and ambient .d.ts type resolution are real issues worth fixing.

However, the current implementation has several concerns:

  1. hasExplicitExportStatement only detects empty export { }, missing other export forms that also make TS treat a file as a module.
  2. extractNamespaceMembers collects non-exported internal members, which would leak private types in the output.
  3. Auto-exporting all declarations from node_modules .d.ts files is too aggressive — should be scoped to actually-referenced types.
  4. Hardcoded reserved keywords list — use @babel/types utilities instead.
  5. Snapshot regressions in existing tests — likely needs a rebase onto latest main.
  6. type-only-import test fixture doesn't actually exercise the scenario it claims to test.

The problems being solved are valid, but the approach needs rethinking. I'd suggest a more targeted solution that only exports types that are actually imported by the consumer, rather than blanket-exporting everything from ambient files.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Feb 2, 2026

Open in StackBlitz

npm i https://pkg.pr.new/rolldown-plugin-dts@175

commit: 3dffe91

@kalvenschraut
Copy link
Copy Markdown
Author

for the export = namespace changes, I had to step back and reapproach them. After some thought I am thinking that rewriting the import to refer to the namespace and export the namespace explicitly is likely a more ideal direction from the two I could come up with AI's help. With the alternative was the original approach and keeping the import as is but generating a ton of type alias's for the namespace imports. The only question I have with this is it exported the the namespace members are not being treeshaken after being pulled in or is that something else I would somehow handle?

Need to try tackle the ambient .d.ts types again, not sure if I will get that where i want it tonight

@socket-security
Copy link
Copy Markdown

socket-security bot commented Feb 3, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedmock-logger@​1.0.0641005375100
Addedmock-db@​1.0.0100100100100100
Addedmock-framework@​1.0.0100100100100100

View full report

@kalvenschraut kalvenschraut marked this pull request as draft February 3, 2026 07:24
@kalvenschraut
Copy link
Copy Markdown
Author

kalvenschraut commented Feb 3, 2026

marked as a draft as I have something mostly working but noticing some cases not covered that need to be fixed.

Would be appreciated to get feedback though to make sure I am heading in the right direction

@kalvenschraut
Copy link
Copy Markdown
Author

There was one more issue I was trying to resolve that I noticed in my company's repo but that is resolved when updating to rolldown rc3 so going call this ready for review. I guess I did have the AI try simplify some things in the types as it ended up changing one of the rollup tests because of that IDK if that is a big problem or not. I was trying get it to not make uneeded namespaces which I thought were from my changes but maybe it wasnt.

@kalvenschraut kalvenschraut marked this pull request as ready for review February 4, 2026 15:08
@kalvenschraut
Copy link
Copy Markdown
Author

kalvenschraut commented Feb 4, 2026

hmm actually noticed that I see have type problems in my companies code base with rc 3, investigating. It is semi related to rolldown/tsdown#755 as if I have it marked as a peer/prod dep it works just fine but once my @types/json-schema is internalize type issues are coming up. if I determine this is a problem not related to this PR I will make a separate one. Realized the other problem was more related to declare module internalization issues as there is already an issue for this so not related

@kalvenschraut kalvenschraut requested a review from sxzz February 4, 2026 17:26
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.

2 participants