我正在使用wasm-bindgen将数据从RUST代码传递到现有的打字代码库.在我的Typescript 中,我有两个界面,一个是InvoiceSchema
,一个是InvoiceWithId
.唯一的区别是InvoiceWithId
也有id
属性.
interface InvoiceSchema { billTo: string, email: string }
interface InvoiceWithId extends InvoiceSchema { id: string }
我知道在Rust中,您不能继承另一个 struct 并添加额外的id
属性,因此我创建了一个 struct :
struct InvoiceWithId {
pub id: String
pub schema: InvoiceSchema
}
在某种程度上,我确实需要将其合并到现有打字代码的单个对象中.
我应该如何转换这些对象并将其传递回TypeScrip,以便id
属性成为基本对象的一部分?即
{ id: string, billTo: string, email: string }