I am using wasm-bindgen to pass data from rust code to an existing TypeScript codebase. In my TypeScript I have two interfaces, a InvoiceSchema and an InvoiceWithId. The only difference is that InvoiceWithId also has an id property.
interface InvoiceSchema { billTo: string, email: string }
interface InvoiceWithId extends InvoiceSchema { id: string }
I understand in Rust, you can't inherit from another struct and add the extra id property so I have created a struct:
struct InvoiceWithId {
pub id: String
pub schema: InvoiceSchema
}
At some point I do need to merge this into a single object for the existing TypeScript code.
How should I convert and pass these objects back to TypeScript so the id property is part of the base object? i.e.
{ id: string, billTo: string, email: string }
You should be able to do this using the
serde-wasm-bindgencrate, which lets you serialize Rust structs to JavaScript values using their serdeSerializeimplementation.