Skip to content

Conversation

schoel-bis
Copy link
Contributor

This fixes #345.

Problem

Module declarations are just copied into the output file verbatim. This breaks for module declarations with relative paths. For example:

declare module "../config" {
  interface Config {
    foo: number;
  }
}

This will just simply be copied, although the relative module path will no longer exist after running this plugin.

This breaks cross-module type extensions with relative paths, i.e. extending the pre-existing Config interface from ../config.ts in the case above.

Solution

To solve this, a new fixer is introduced that rewrites all relative module declarations in such a way, that they reference the output file itself, i.e. if the output file were called index.d.ts, the above would be rewritten as:

declare module "./index" {
  interface Config {
    foo: number;
  }
}

Now, the pre-existing interface taken from ../config.ts will be properly extended again.

@Swatinem Swatinem merged commit e343998 into Swatinem:master Aug 22, 2025
4 checks passed
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.

Produces wrong output for declare module statement with relative path
2 participants