typeshare icon indicating copy to clipboard operation
typeshare copied to clipboard

Enum types are not topologically sorted

Open Bushuo opened this issue 5 months ago • 1 comments

First of all, thank you for this great crate. I use it a lot in my project (for which I made a fork and implemented rescript support, probably not complete). In rescript all types inside a module need to be topologically sorted by dependency.

I expanded on the snapshot test orders_types with the following. Purposefully named such that BEnum should be declared before AEnum after sorting.

#[typeshare]
#[serde(rename_all = "camelCase", tag = "type", content = "data")]
pub enum AEnum {
    Variant1(BEnum),
    Variant2(f32),
}

#[typeshare]
#[serde(rename_all = "camelCase")]
pub enum BEnum {
    Var1,
    Var2,
}

Expected

type bEnum =     | @as("var1") var1      | @as("var2") var2

@tag("type")
type aEnum =
         | @as("variant1") variant1({data: bEnum})
         | @as("variant2") variant2({data: float})

Actual

@tag("type")
type aEnum =
         | @as("variant1") variant1({data: bEnum})
         | @as("variant2") variant2({data: float})

type bEnum =     | @as("var1") var1      | @as("var2") var2

If I reverse the names of the types the output is correct. So I guess they are sorted alphabetically beforehand. I guess kotlin is also terse with enum output so you could verify there.

Bushuo avatar Oct 29 '25 21:10 Bushuo