typeshare icon indicating copy to clipboard operation
typeshare copied to clipboard

Figure out how to handle scenarios where enum variants contain data types with the same name

Open snowsignal opened this issue 2 years ago • 1 comments

If we have an enum that contains a data type with an identical name, the generated code will be ambiguous and throw errors.

Here's an example of code that would cause this problem.

#[typeshare]
struct Variant {}

#[typeshare]
#[serde(tag ="type", content ="content")]
pub enum MyEnum {
    Variant(Variant),
}

One potential workaround is creating type-aliases to resolve the ambiguous typing, but this solution needs further exploration to ensure we won't create further naming conflicts by accident.

snowsignal avatar Jan 09 '23 18:01 snowsignal

Maybe you can use config as well?

[typescript.type_mappings]
"Variant" = "AnotherName"

Would that not work?

ls-ivan-kiselev avatar Feb 21 '23 13:02 ls-ivan-kiselev