Open richvdh opened 1 year ago
(I think this is blocked on better support in wasm-bindgen
?)
Yeah, it should be patched on wasm-bindgen
directly.
@Hywan is there a particular issue in the wasm-bindgen
repo which tracks the features we need here?
I don't think so. The best I can find is https://github.com/rustwasm/wasm-bindgen/issues/1197.
FWIW with modern wasm-bindgen, we can improve on this considerably: wasm-bindgen
now understands async
functions and will automatically turn async fn foo() -> Bar
into javascript-side functions that return Promise<Bar>
, provided Bar
has an Into<JsValue>
impl (cf https://rustwasm.github.io/wasm-bindgen/reference/js-promises-and-rust-futures.html#return-values-of-async-fn).
We should go through and fix the existing methods that explicitly call future_to_promise
, and stop adding new ones.
Oh nice!
Currently,
matrix-sdk-crypto-js
defines lots of functions which return types likePromise
, rather than using typescript's support for generics to declare what that promise will contain.For example:
OlmMachine.getMissingSessions
could be defined to returnPromise<KeysClaimRequest | undefined>
.Failure to declare these types correctly (a) makes development against the library much harder, because application developers have to add their own type annotations; (b) increases the risk of a regression due to an unnoticed change in return value