-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attribute for externally tagged enums or match serde by default #38
Comments
I'm currently working on this. |
What's working so far: #[derive(TS)]
enum SimpleEnum {
A(String),
B(i32),
C,
D(String, i32),
E(Foo),
F { a: i32, b: String },
} generates (output formatted) type SimpleEnum =
| { A: string }
| { B: number }
| "C"
| { D: [string, number] }
| { E: Foo }
| { F: { a: number, b: string } }; Which does seem to match serdes default "externally tagged" representation: {"A":"foo"}
{"B":5}
"C"
{"D":["bar",123]}
{"E":{"bar":{"field":44}}}
{"F":{"a":42,"b":"baz"}} |
though #[ts(inline)] is not behaving like it should |
fixed in v6.0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
currently the the TS::decl() generated for a type like
looks like this
whereas serde_json generates output matching the type
serde-compat
allows for matching other styles of representing enums, like#[serde(tag = "tag", content = "content")]
, but there's no way to match the default since there's no serde attribute for it. I think matching serde's default output is preferable since it allows for differentiating betweenA("C")
andC
, but an attribute would work too.The text was updated successfully, but these errors were encountered: