-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generate TypeScript return types for async
functions
#2665
Generate TypeScript return types for async
functions
#2665
Conversation
Per the docs, returning
These tests are now failing, whereas before the non- #[wasm_bindgen]
pub async fn async_return_7() -> Result<AsyncCustomReturn, u32> {
Ok(AsyncCustomReturn { val: 7 })
}
#[wasm_bindgen]
pub async fn async_return_8() -> Result<AsyncCustomReturn, AsyncCustomReturn> {
Ok(AsyncCustomReturn { val: 8 })
}
#[wasm_bindgen]
pub async fn async_throw() -> Result<(), js_sys::Error> {
Err(js_sys::Error::new("async message"))
}
And indeed, they don't work when removing the |
Thanks for the PR! The implementation here looks pretty reasonable to me. I think it's fine to update those tests as well, yeah. Can you add some specific tests for this new feature though? Ideally there'd be reference tests to see the output, tests in the main tests suite to exercise that things work, and tests in the typescript area to ensure that everything typechecks as expected. |
@alexcrichton Thanks for the review! I added a test in the typescript-tests area. I don't see any existing reference tests at all for Also, the only intended output change is to the |
Nah this looks good to me, thanks! |
Threads through an
asyncness
bool and an "inner" return value type descriptor for functions, then generatesPromise<...>
return types forasync
functions.Fixes #2394