specta-rs / specta

Easily export your Rust types to other languages
MIT License
291 stars 41 forks source link

[Discussion] Plans to support duplicate type names? #62

Open ajmcquilkin opened 1 year ago

ajmcquilkin commented 1 year ago

Just submitting this to see if there's any plans to support exporting types with duplicate names. I would love to use specta on a project with auto-generated Rust types with significant numbers of duplicate type names. I can imagine a somewhat direct mapping for duplicate type names existing between Rust modules and TypeScript namespaces, although I can't speak to mappings from Rust modules in other languages.

On a side note, in the event that an equivalent of Rust's module system doesn't exist in a given export language target, this could then throw a DuplicateTypeName error when a user attempts to export to this language.

Within the test_duplicate_ty_name test, I could imagine the following to be a valid TypeScript export from the Rust test modules provided:

namespace one {
    const One = { /* ... */ };
}

namespace two {
    const One = { /* ... */ };
}

const Demo = { one: one.One, two: two.One };

I don't have much context on what this would take technically to implement, but I'd be happy to investigate if this is something the project would be interested in.

oscartbeaumont commented 1 year ago

I would be willing to support this but I would prefer it if using it was a configuration similar to the current handling of bigints with the options Enabled, Error or something like that.

@Brendonovich has been pushing me towards inlining all of the types in rspc to avoid naming as a problem so having this configuration as an enum would make it possible for me to handle that when I come to implement it.

I don't see myself working on this any time soon but a PR would be welcome. Hit me up on Discord or here if you wanna chat more about specifics if you were going to do a PR.

Binlogo commented 5 months ago

I'm experiencing the same issue with duplicate type names in different Rust modules when using rspc for Rust and TypeScript communication.

I see there's already a draft PR (#72) addressing this, great job, @ajmcquilkin 👍. Could you share the current progress and status? I'd be happy to assist or discuss further to help move this forward.

Thanks.

oscartbeaumont commented 5 months ago

At this stage it's on me to find some time and get it merged back into main because a lot of stuff has a changed since the PR was opened. Definetly my bad for not getting the PR reviewed and merged ealier.