Skip to content

Add toExports support for declaration files #472

Closed

Description

@8ctavio

Describe the feature

toExports may be used to populate a declaration file (like Nuxt for #imports type support). When this is the case, toExports should be able to take module names from Import entries' typeFrom property, if provided:

const imports = [{ from: 'pkg/src', typeFrom: 'pkg/dts', name: 'foo' }]
toExports(imports, /* enable d.ts support */) // export {foo} from 'pkg/dts'

Currently, toExports uses the from property exclusively. If typeFrom is provided but from is used, typescript might not be able to find the module's declaration files.

(also see nuxt/nuxt#33372).

Proposed API

For compatibility, a new options parameter may be added to toExports:

declare function toExports(
  imports: Imports[],
  fileDir?: string,
  includeType?: boolean,
  options?: { declaration: boolean; }
): string

In the future, fileDir and includeType could be incorporated into options.

const imports = [{ from: 'pkg/src', typeFrom: 'pkg/dts', name: 'foo' }]
toExports(imports)                                        // export {foo} from 'pkg/src'
toExports(imports, undefined, false, {declaration: true}) // export {foo} from 'pkg/dts'

I could submit a PR to implement this apporach.

Additional information

  • Would you be willing to help implement this feature?

Activity

  1. added
    enhancement
    on Oct 1, 2025
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

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions