Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wrong d.ts generated when importing same name classes with alias #136

Closed
hdmr14 opened this issue Jan 28, 2021 · 2 comments
Closed

wrong d.ts generated when importing same name classes with alias #136

hdmr14 opened this issue Jan 28, 2021 · 2 comments
Labels
Bug Something isn't working

Comments

@hdmr14
Copy link

hdmr14 commented Jan 28, 2021

  • Version: 1.3.8
  • Rollup Version: 2.38.0
  • TypeScript Version: 4.1.3

Reproduction

  1. create a class module with the same name in different named files (b.ts and b2.ts)
  2. import them to same place(index.ts) using alias
  3. export something using them(it just re-exported them in Repl)
  4. wrong d.ts generated(js is fine)

Here's Repl:
https://repl.it/@hdmr14/wrong-type-declaration
Config file:
https://repl.it/@hdmr14/wrong-type-declaration#rollup.config.js
Generated files:
https://repl.it/@hdmr14/wrong-type-declaration#out/index.d.ts
https://repl.it/@hdmr14/wrong-type-declaration#out/index.js

Expected Behavior

it should be based on the generated js code.

declare class B {
}
declare class B$1 {
}
type B2 = B$1;
export { B, B2 };

or some BWrappers generated?

Actual Behavior

unexpected BWrapper generated

declare class B {
    b(): void;
}
declare module BWrapper {
    export { B };
}
import B2 = BWrapper.B$0; // <= B$0 not declared
export { B, B2 };
@wessberg
Copy link
Owner

wessberg commented Apr 13, 2021

That's definitely a bug. Thanks for the repro, I'll look into it.

As for why there's a ModuleDeclaration in there and we don't do a TypeAliasDeclaration such as you suggest (type B2 = B$1), there's actually a very good reason for it, and you can read more about it here. Classes are treated a little bit different than other types in TypeScript and type aliases cannot be instantiated.

The correct output should have been:

declare class B {
}
declare class B$0 {
}
declare module BWrapper {
    export { B$0 as B };
}
import B2 = BWrapper.B;
export { B, B2 };

@wessberg wessberg added the Bug Something isn't working label Apr 13, 2021
@wessberg
Copy link
Owner

This has been fixed and was caused by the deconflicting logic of the declaration bundler not handling QualifiedName nodes. A new version will be released on NPM shortly containing this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants