Skip to content

Fix type-only exports#748

Merged
cenk1cenk2 merged 3 commits into
listr2:masterfrom
karlhorky:patch-3
Sep 2, 2025
Merged

Fix type-only exports#748
cenk1cenk2 merged 3 commits into
listr2:masterfrom
karlhorky:patch-3

Conversation

@karlhorky

@karlhorky karlhorky commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

Closes #745

The previous approaches didn't lead to dist/index.d.ts containing the type keyword in the exports for ListrTaskObject and ListrTaskWrapper:

This appears to be caused by the export * from './interfaces' here, which converts the type-only exports into non-type-only exports:

export * from './interfaces'

I tried a new approach, of using the type keyword at the top-level src/index.ts file, and that appears to generate the correct types in dist/index.d.ts.

Proof (type keywords in dist/index.d.ts):

Screenshot 2025-08-21 at 14 13 08

@cenk1cenk2

Copy link
Copy Markdown
Member

This is interesting, it did not act like this before. But also a bit dangerous since I have to go through inferfaces now and see whether we need something as concrete and not just type.

@karlhorky

Copy link
Copy Markdown
Contributor Author

I'm assuming this just affects classes, since interface and type do not have runtime counterparts...

@karlhorky

Copy link
Copy Markdown
Contributor Author

@cenk1cenk2 what do you think about merging only this change as-is to start? Or, if that's not ok, what would you like to see here before merging?

@cenk1cenk2

cenk1cenk2 commented Sep 2, 2025

Copy link
Copy Markdown
Member

Hey @karlhorky,

Sorry for the delay, I do not get what is the difference between moving the type export exactly as a type export from a file to the index.

Does this solve your issue?

@karlhorky

karlhorky commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Yes, it resolves my issue - I built locally and tested this (also mentioned in the PR description above):

Proof (type keywords in dist/index.d.ts):

The previous version didn't work: #747 (comment)

I don't know what the difference is either, but I would assume that tsdown or some other part of the build turns exported type-only exports into type + runtime exports when using the export * from './interfaces' pattern.

Current (broken)

packages/listr2/src/index.ts

export * from './interfaces'

packages/listr2/src/interfaces/index.ts

export type { Task as ListrTaskObject, TaskWrapper as ListrTaskWrapper } from '@lib'

Output:

export { ... TaskWrapper as ListrTaskWrapper, ...

After this PR (fixed)

packages/listr2/src/index.ts

export { ... type Task as ListrTaskObject, type TaskWrapper as ListrTaskWrapper } from './lib'

Output (note the type keyword inside the curly brackets):

export { ... type TaskWrapper as ListrTaskWrapper, ...

@cenk1cenk2

Copy link
Copy Markdown
Member

Thank you for the explanation yet again.

@cenk1cenk2
cenk1cenk2 merged commit 45d199d into listr2:master Sep 2, 2025
5 checks passed
@karlhorky

karlhorky commented Sep 2, 2025

Copy link
Copy Markdown
Contributor Author

Reported the export * flattening + type qualifier dropping problem in rolldown-plugin-dts and rollup-plugin-dts too:

@karlhorky

Copy link
Copy Markdown
Contributor Author

@cenk1cenk2 if you would publish a new release with this change, I'll take a look to verify it's working.

@cenk1cenk2

Copy link
Copy Markdown
Member

Ah i see it did not match eoth the commits so did not publish, sorry missed that. I will trigger one when infront of computer.

Sorry for that.

@cenk1cenk2

Copy link
Copy Markdown
Member

🎉 This PR is included in version 9.0.4 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@cenk1cenk2

Copy link
Copy Markdown
Member

🎉 This PR is included in version 3.0.4 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@cenk1cenk2

Copy link
Copy Markdown
Member

🎉 This PR is included in version 3.0.4 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@cenk1cenk2

Copy link
Copy Markdown
Member

🎉 This PR is included in version 3.0.4 🎉

The release is available on npm package (@latest dist-tag)

Your semantic-release bot 📦🚀

@karlhorky

Copy link
Copy Markdown
Contributor Author

Nice, thanks for the release!

I can confirm that [email protected] now displays errors with importing ListrTaskWrapper without a type keyword when verbatimModuleSyntax: true is present in tsconfig.json 🎉

Image
'ListrTaskWrapper' resolves to a type-only declaration and must be imported using a type-only import when 'verbatimModuleSyntax' is enabled. ts(1485)

@karlhorky
karlhorky deleted the patch-3 branch September 16, 2025 14:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: no error with runtime ListrTaskWrapper import with verbatimModuleSyntax: true in tsconfig.json

2 participants