madonoharu / tsify

A library for generating TypeScript definitions from rust code.
Apache License 2.0
300 stars 41 forks source link

How to deal with enum Type union when serde is shared with a key-less format? #18

Open Vloz opened 1 year ago

Vloz commented 1 year ago

Trying to send decoded postcard to js.

Postcard prevent serde to configure enum representation with macro like #[serde(tag = "t", content = "c")] , crashing with a WontSupport error.

The default variant enum then export as:

export type SocketMessage = "Ok" | { Error: { details: string } } | ...

It seems pretty un-usable compared to union with a dedicated key attribute (which type are deduced from key by the editor with if and switch statement).

Any idea to enforce Adjacently tag as wasm_typescript_definition does without using serde(tag = "t", content = "c"?

For the moment i am using a factory to turn the initial struct to another that allow the serde macro.