typeshare icon indicating copy to clipboard operation
typeshare copied to clipboard

Supporting algebraic enums without the content attribute

Open FlorianDenis opened this issue 1 year ago • 1 comments

I realize this is something that is not currently supported; This is something that would hugely increase the benefit of this tool for me.

To be clear, I am talking about

#[typeshare]
#[derive(Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "camelCase")]
pub enum MyEnum {
    A,
    B {
        field1: String,
        field2: u32,
    },
}

which I would like to have generated (in TS for instance) as

type MyEnum =
    | { type: "a" }
    | { type: "b", field1: string, field2: number }

I want to dig a bit more into the reasons why this choice was made and how we could potentially move forward.

Was this not added because:

  1. You tried to implement it and encountered roadblocks?
  2. You have no use internally for it? In which case, would you be open to contributions allowing this? This would not necessitate a major version bump right, this would just be a non-breaking addition on the current features, or am I missing something ?

FlorianDenis avatar Aug 30 '23 11:08 FlorianDenis

To support the idea, I started working on a draft implementation supporting all languages but Go: see https://github.com/1Password/typeshare/pull/142/

FlorianDenis avatar Sep 04 '23 09:09 FlorianDenis