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

Handling Name Conflicts in Struct Exports Across Modules #130

Open
alimehasin opened this issue Sep 10, 2024 · 1 comment
Open

Handling Name Conflicts in Struct Exports Across Modules #130

alimehasin opened this issue Sep 10, 2024 · 1 comment

Comments

@alimehasin
Copy link

I've encountered an issue where having two structs with the same name across multiple modules results in them overwriting each other during type exports. This led to some confusion on my part, and I found it necessary to rename several structs to address the problem.

I believe that structs should not share the same name, even if they are in different modules. Could we consider either implementing a solution that allows exporting types with unique names or introducing an error when such naming conflicts occur?

@oscartbeaumont
Copy link
Member

The fact that duplicate named structs are overriding each other is definetly a bug, they should error on export so will keep this issue open for tracking a fix for that.

I personally think Specta should never mess with the naming of the structures because the types can be imported and used by Typescript code so the user should be in charge of some explicit mapping (the name) between the Rust and Typescript types.

Potential Solutions:

  • Just rename it. Having multiple identically named types can be confusing with LSP/code readability. Eg. struct MyNewName
  • Use #[specta(rename = "abc)] on the struct. This will change the Typescript name.
  • In the future we will also support Typescript namespaces.

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

2 participants