typeshare icon indicating copy to clipboard operation
typeshare copied to clipboard

Typescript: `unit` seems to be wrongly defined as `undefined` in Typescript

Open d4h0 opened this issue 2 years ago • 1 comments

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).

d4h0 avatar Dec 24 '22 12:12 d4h0

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.

LuminaSapphira avatar Apr 13 '23 18:04 LuminaSapphira