typeshare icon indicating copy to clipboard operation
typeshare copied to clipboard

Support serde-wasm-bindgen

Open stefnotch opened this issue 2 years ago • 3 comments

When using Rust together with Javascript, one common way of doing so is by using wasm-bindgen.

However, wasm-bindgen does not recommend using the default serde approach for converting Rust to Javascript. Instead they recommend using serde-wasm-bindgen. This is also the first recommended approach in their documentation.

The problem is that serde-wasm-bindgen does a few things rather differently. For example, Rust HashMaps are turned into Javascript Maps This, of course, doesn't line up with what the typeshare crate offers.

Sadly the lovely developers of serde-wasm-bindgen have deemed generating Typescript as "out of scope", hence I'm opening an issue here. I wanted to ask if it would be in-scope to support that use-case? Or if I should raise an issue elsewhere.

For completeness sake, there's a smaller, less maintained crate that seems to be able to generate the correct types when using serde-wasm-bindgen https://github.com/madonoharu/tsify

stefnotch avatar Apr 15 '23 15:04 stefnotch

Thanks for submitting this issue. Right now this is out of scope but we are aiming to provide support for wasm targets in the future.

sanjanadesai27 avatar May 15 '23 17:05 sanjanadesai27

Thanks for the clear response! Then I'll look forward to what you'll do in the future, and for now either

  • use the default Serde JSON approach together with this library
  • or maintain Typescript types by hand

And for the future, I'll

  • continue to watch this library
  • experiment with the WebAssembly Interface Types once they become viable https://github.com/bytecodealliance/wit-bindgen

stefnotch avatar May 16 '23 08:05 stefnotch

Then I'll look forward to what you'll do in the future, and for now either

  • use the default Serde JSON approach together with this library
  • or maintain Typescript types by hand

FWIW you (and anyone else coming across this issue) might want to look into tsify which supports generating TS defintiions and works in conjunction with serde-wasm-bindgen.

RReverser avatar Jan 16 '24 19:01 RReverser