feat(toExports): add `declaration` option to generate exports for declaration files by 8ctavio · Pull Request #477 · unjs/unimport · GitHub
Skip to content

feat(toExports): add declaration option to generate exports for declaration files#477

Merged
antfu merged 3 commits intounjs:mainfrom
8ctavio:feat-1
Dec 14, 2025
Merged

feat(toExports): add declaration option to generate exports for declaration files#477
antfu merged 3 commits intounjs:mainfrom
8ctavio:feat-1

Conversation

@8ctavio
Copy link
Copy Markdown
Contributor

@8ctavio 8ctavio commented Oct 9, 2025

Resolves #472

  • Add a new options parameter to toExports. As mentioned in the issue, other parameters could be incorporated to options in the future.
  • Add ToExportOptions.declaration to read from imports' typeFrom if provided.
  • In toImportModule, use typeFrom instead of from if provided and options.declaration is true. This causes toExports to use typeFrom as the specifier for generated exports.

@8ctavio 8ctavio changed the title Feat 1 feat(toExports): use typeFrom to generate exports for declaration files Oct 9, 2025
@8ctavio 8ctavio changed the title feat(toExports): use typeFrom to generate exports for declaration files feat(toExports): add declaration option to generate exports for declaration files Oct 9, 2025
@codecov
Copy link
Copy Markdown

codecov Bot commented Oct 9, 2025

Comment thread test/to-export.test.ts
]
expect(
toExports(imports, undefined, false, { declaration: true }),
).toMatchInlineSnapshot(`"export { foo } from 'pkg/dts';"`)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change

Should it be like this as well?

Copy link
Copy Markdown
Contributor Author

@8ctavio 8ctavio Oct 28, 2025

Choose a reason for hiding this comment

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

It seems that toExports does not currently emmit export type, and typeFrom is only concerned with the specifier; but since declaration: true is supposed to be used for declaration files, generating type-only exports with the export type {} from syntax may also be supported.

Imports, however, are "marked" as type-only with the Import.type option. Perhaps when includeType and declaration are set to true, toExports should use export type {} for type-only imports (those with type: true). For reference, generateTypeDeclarations uses toTypeReExports for type-only imports.

@antfu antfu merged commit 225588b into unjs:main Dec 14, 2025
4 of 5 checks passed
@8ctavio 8ctavio deleted the feat-1 branch January 20, 2026 14:11
This was referenced Feb 17, 2026
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.

Add toExports support for declaration files

2 participants