typeshare
typeshare copied to clipboard
Supporting algebraic enums without the content attribute
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:
- You tried to implement it and encountered roadblocks?
- 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 ?
To support the idea, I started working on a draft implementation supporting all languages but Go: see https://github.com/1Password/typeshare/pull/142/