Skip to content

Please reconsider including types condition during auto-export creation #875

Closed as not planned

Description

@dever23b

Clear and concise description of the problem

Hello:

I recently discovered this project and, firstly, thank you! I was really struggling with figuring out tsconfigs for different packages in a monorepo, and specifically exporting a shared lib to be consumed by both Node.js and a browser environment. This project reduced hours of suffering into a few minutes!

This brings me to my request, and I'm hoping the context will justify it. I am requesting that you reconsider incorporating the work that was done in #253 and #307 and generate a "types" condition export for each entry.

Your comments indicate that the "types" condition is not required, because TypeScript will automatically look for an ambient declaration file when importing. While this true, this behavior is limited to full imports: it does not occur for type-only imports (import type { ... } from ... or import { type ... } from ...). While I freely admit that I am not a savant with TypeScript and there may be better ways to accomplish the goal, there are occasions where I have found it necessary to do type-only imports, as a full import breaks code or creates a circular redundancy. I understand that the "types" condition is not required; however, in these situations, it would be very helpful and I'm not aware of any downsides to it.

I wrote a workaround using the customExports feature that takes a guess at where the ambient declaration file should be and adds a "types" condition. It "works", but it makes some unsafe assumptions: it's fine for my private project, but I wouldn't trust it for public consumption. Furthermore, despite working on it for awhile, I wasn't able to figure out how to access enough data to remove the assumptions and definitively assert the location of the proper declaration files.

Thanks for your time and work on this project

Suggested solution

Based on a review of of generateExports, it seems like it may be possible to add a format for ambient declarations. Then, instead of continuing if the chunk is not an ES or CJ module, you could capture ambient declarations and then store that chunk to subExport for inclusion during genSubExport.

Obviously, I'm no expert at this (or I probably wouldn't have to resort to a cool package like this to bundle my code) and it feels silly to make code suggestions at my experience level. But, it would be really helpful if tsdown generated type conditions and I didn't want to make a request without offering a potential solution.

Alternative

No response

Additional context

No response

Validations

Activity

  1. added
    enhancement
    on Mar 28, 2026
  2. added theissue type on Mar 28, 2026
  3. github-actions commented on Mar 28, 2026

    @github-actions

    Hello @dever23b! 👋

    Thank you for raising an issue. However, we need a minimal reproduction to investigate the problem effectively.

    📋 What is a Minimal Reproduction?

    A minimal reproduction is the smallest possible project that demonstrates your issue. It should:

    • Include only the code necessary to reproduce the issue
    • Remove all unrelated dependencies and code
    • Be as simple as possible while still showing the problem

    Learn more about why reproductions are required: Why Reproductions are Required

    🔧 How to Provide a Reproduction

    Choose one of the following options:

    1. Use StackBlitz (Recommended for quick sharing)

    2. Use a GitHub Repository

      • Fork this template
      • Create a minimal reproduction
      • Share your repository link

    💡 Need Help?

    If you're having trouble creating a reproduction or need debugging assistance, consider using Priority Support for dedicated help!


    Once you've provided a minimal reproduction, please comment here with the link. We'll be happy to investigate further. Thank you for your understanding! 🙏

  4. sxzz commented on Mar 28, 2026

    @sxzz
    Member

    Thanks for the detailed write-up! Could you provide a minimal reproduction that demonstrates the case where the missing types condition causes an issue? For example, a small repo or StackBlitz showing the type-only import failing to resolve without it. That would help us understand exactly under which circumstances this is needed and evaluate the best approach.

  5. dever23b commented on Mar 28, 2026

    @dever23b
    Author

    Sure! I think I can figure that out. Let me work on it and get back to you.

  6. dever23b commented on Mar 29, 2026

    @dever23b
    Author

    Well, I have to admit, I'm completely stumped. I was not able to reproduce the issue.

    I re-created the design pattern I'm using in a test repo and, when that worked, I rolled back my main project to before I created the customExports workaround and found that that was also working just fine. My best guess is that I got bit again by VS Code and its TS Server randomly acting up.

    At the time I submitted this issue, I was consistently getting "Module module has no exported member member" errors on any import type statements, and the error seemed directly tied to whether my shared lib exported a types condition. If I re-built the lib with types conditions on each export, the main project would see the modules; if I removed the types condition, the main project would get flooded with module errors. I tested it several times, but didn't think to restart my TS Server before came here for help.

    I did extensive testing with different configurations, playing with combinations of customExports and devExport settings. Not only was I unable to reproduce this issue, I couldn't produce any issues. Tsdown is performing perfectly, and I'm very happy with it.

    Thanks for the quick response and all your work on this project. It seems I've wasted your time, unfortunately, and I'm sorry about that.

  7. locked and limited conversation to collaborators on Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementneeds reproduction

    Fields

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions