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

Bundle introduces a type that references to itself #325

Open
3 tasks done
notaphplover opened this issue Nov 29, 2024 · 1 comment
Open
3 tasks done

Bundle introduces a type that references to itself #325

notaphplover opened this issue Nov 29, 2024 · 1 comment

Comments

@notaphplover
Copy link

notaphplover commented Nov 29, 2024

The bundler seems to be removing type aliases that leads to circularly referenced types.

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

import { foo as namedFoo } from '@foo/package';

namespace myAwesomeNamespace {
  export type foo = namedFoo;
}

Error Message

The bundled code is the following one:

import { foo } from '@foo/package'; // Unused import

declare namespace myAwesomeNamespace {
  export type foo = foo; // Type alias 'foo' circularly references itself.ts(2456)
}
@notaphplover
Copy link
Author

notaphplover commented Nov 29, 2024

For those experiencing this issue, you can workaround it introducing some redundacy the bundler cannot detect. An example to workaround my sample code would be:

import { foo } from '@foo/package';

// This type has the only purpose of introducing a redundancy
type Identity<T> = T

type namedFoo = Identity<foo>;

namespace myAwesomeNamespace {
  export type foo = namedFoo;
}

Thanks to the undetected redundacy, namedFoo is not removed and there will be no circular dependencies in the bundled types. It's sort of ugly, but works. Any other undetected redundancy might be use to workaround this issue.

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

No branches or pull requests

1 participant