mars-protocol / rover

Smart contracts for Rover
GNU General Public License v3.0
1 stars 1 forks source link

Typesafe wasm exports #165

Closed grod220 closed 1 year ago

grod220 commented 1 year ago

At the moment, the functions that wasm-bindgen exports are not typesafe: https://github.com/mars-protocol/rover/blob/master/scripts/health/pkg-web/index.d.ts#L4-L20. Due to javascript serialization, it renders the arguments and return value as any. This breaks the tight coupling of the rust code to typescript. Over time, this will allow bugs to slip in unnoticed.

This PR utilizes a library called Tsify that is designed to be an attribute where you can derive what is needed for the wasm_abi. This means the exported functions can use normal structs and the types exported are no longer anys! Frontend gets strong typing and breaking code guarantees frontend will know.