Skip to content

export type vs export { type } with augmentations #63061

@skirtles-code

Description

@skirtles-code

🔎 Search Terms

augmentation
export
augmentation type implicit import

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about augmentation.

I couldn't find any FAQ entries about augmentation.

Among others, I tried 5.9.3, the current nightly, and 4.5.5.

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.9.3#code/CYUwxgNghgTiAEBbA9sArhBByEAPKiADplvAN4BQ88ehyMALvAwJ6EIAiAlnGAxCwCiuOoxDB4AXnhoAdgGtZyAO6yqzNggCSs4D3D8hI+g3FSZCpavW0T5De3g69vQ8NGmJAXwo+KoSFgEFHRMeBx8IhJydVZHAHV6eQBnc25XAXcTcVjNeA5kEGSAOWQGRJh5c2d9PkzjMWAKAHpm6naOzs6APV6+-oG+lraAYShZJSYAMy5deFkCbBqMow9xLAA6XyA

💻 Code

declare module 'example' {
  export type DirectlyExported = unknown
  type IndirectlyExported = unknown
  export { type IndirectlyExported }
}

declare module 'example' {
  type Works = DirectlyExported
  type DoesNotWork = IndirectlyExported
//                   ^^^^^^^^^^^^^^^^^^
// Cannot find name 'IndirectlyExported'.
}

🙁 Actual behavior

There's an inconsistency between export type and export { type }. The latter doesn't seem to allow augmentations to access the type.

🙂 Expected behavior

export { type } should behave like export type for augmentations.

Additional information about the issue

I initially asked about this on the TypeScript Discord, https://discord.com/channels/508357248330760243/1466086808231350531. The Playground I shared above was suggested by someone in the discussion there, as my original example needed multiple files.

The background is that I'm trying to migrate a library from Rollup to Rolldown. The types generated by the existing Rollup build look a bit like this in the .d.ts file:

export declare type Foo = 'A';
export {}

The new Rolldown build is generating this:

type Foo = 'A';
export { type Foo };

These are then used in the consuming application to augment the types of the library, e.g.:

declare module 'library-name' {
  export interface Baz {
    bar: Foo
  }
}

export {}

With the first .d.ts file this works fine, but with the second .d.ts file the type Foo needs to be explicitly imported.

If TypeScript is working as intended then this may need changes to the d.ts generation in Rolldown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions