tsify icon indicating copy to clipboard operation
tsify copied to clipboard

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

Open Vloz opened this issue 1 year ago • 0 comments

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.

Vloz avatar Apr 25 '23 17:04 Vloz