typeshare
typeshare copied to clipboard
Typescript: `unit` seems to be wrongly defined as `undefined` in Typescript
Hi,
I've the following Rust code:
#[derive(Debug, serde::Serialize)]
#[typeshare::typeshare]
#[serde(tag = "type", content = "content")]
pub enum Cmd {
StartBrowser(StartBrowser),
}
#[derive(Debug, serde::Serialize)]
#[typeshare::typeshare]
pub struct StartBrowser(pub ());
...which generates the following Typescript code:
export type StartBrowser = undefined;
export type Cmd =
| { type: "StartBrowser", content: StartBrowser };
...however, serde_json
serializes Cmd::StartBrowser(StartBrowser(()))
as {"type":"StartBrowser","content":null}
(please note the null
instead of the above defined undefined
).
I'm not 100% sure, but I believe serde_json
uses undefined
to represent optional values (i.e., Rust's Option
type).
We ran into some issues wherein previously working FFI calls in downstream projects broke. As a result in #97 the changes were reverted. This is still on our radar, but we'd ideally want to avoid breaking our downstream projects. In the meantime, further discussion can be held here.