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

namespace exports circularly references themselves #223

Closed
3 tasks done
kraenhansen opened this issue Sep 21, 2022 · 3 comments
Closed
3 tasks done

namespace exports circularly references themselves #223

kraenhansen opened this issue Sep 21, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@kraenhansen
Copy link

kraenhansen commented Sep 21, 2022

Checklist

  • I can reproduce this issue when running this plugin on its own.
    Other plugins, such as node-resolve are known to cause issues.
  • I am running this plugin on .d.ts files generated by TypeScript.
    The plugin can consume .ts and even .js files (with allowJs: true), but this is known to cause issues.
  • This issue is not related to rolling up @types.
    The plugin ignores these by default, unless respectExternal is set. @types can contain hand-crafted code which is known to cause issues.

Code Snipped

I've pushed a reproduction of this https://github.com/kraenhansen/rollup-plugin-dts-issue-223

// thing.ts
export class Thing {};
// index.ts
import * as thing from "./thing";
export namespace MyNamespace {
  export type Thing = thing.Thing;
}

Results in the following output:

// types.d.ts
declare class Thing {
}

declare namespace MyNamespace {
    type Thing = Thing;
}

export { MyNamespace };

Error Message

The type Thing = Thing; in the output file above yields:

Type alias 'Thing' circularly references itself.

Which effectively results in the type being any for a consumer (see consumer.ts in the reproduction).

Workaround

Note that if I add a local type alias in the index.ts, the output turns out as expected:

// index.ts
import * as thing from "./thing";
type MyThing = thing.Thing;
export namespace MyNamespace {
  export type Thing = MyThing;
}

yields

// types.d.ts
declare class Thing {
}

declare type MyThing = Thing;
declare namespace MyNamespace {
    type Thing = MyThing;
}

export { MyNamespace };
@Swatinem
Copy link
Owner

Swatinem commented Oct 9, 2022

Thanks for the report!
This is unfortunately a restriction that TS does variable hoisting for namespaces. Working around this is annoying and fragile :-(

@kraenhansen
Copy link
Author

@Swatinem how / when was this fixed?

@Swatinem
Copy link
Owner

I mass-closed all the issues, as I transition the project into maintenance mode and won’t be working on any of it, see #277
However I wasn’t able to mass-close-and-comment mentioning that.

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