-
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
Functions returning Result<T,E> result in incorrect typescript function output type Array
#4207
Comments
Cannot reproduce. I just tested your code on |
Huh, that's weird. Before opening this issue, I specifically started a fresh project without |
This is dependent on the rust version! Something has happened between Rust 1.81 and 1.82 that triggers this behavior. Using the code from the original post, I can reproduce it like this using wasm-bindgen 0.2.95:
Gives me
Note that I got this behavior for a lot of functions/method on another project, and it doesn't seem to be related to Result specifically. I can not reproduce it on wasm-bindgen 0.2.93, with either Rust version |
Now I understand what's going on here. Rust 1.82 enabled multivalue returns by default (related #4133). This allows wasm-bindgen to directly return multiple value instead of using a return pointer. WBG returns multiple values, because it needs a tag for the result (one value) and the error (another value) for This is why the signature changed from That said, I don't see why this is an issue. From my understanding, this is just wasm bindgen's internal ABI for those functions, and this ABI may change at any time and depending on configuration (e.g. compiler flags). The generated JS function of the same name should still be |
It is an issue because the type signature in the generated .d.ts bindings is invalid! I.e. Typescript applications that load these definition files won't compile. (I'm not actually sure why these "internal" functions end up in the Typescript definitions in the first place, preferably I'd rather not have them there at all, but that's another topic) |
Oh, I didn't even notice that. I thought the issue was about the function return an array instead of Well, replacing
I super agree. I don't know why there are exported at all. |
Signed-off-by: John Kastner <[email protected]>
Signed-off-by: John Kastner <[email protected]>
Signed-off-by: John Kastner <[email protected]>
Signed-off-by: John Kastner <[email protected]>
Describe the Bug
In version 0.2.95, any function returning a
Result<T,E>
will cause the generated typescript function to returnArray
(note that it's notArray<T>
, justArray
). The problem doesn't occur in version 0.2.93.Steps to Reproduce
Using the code from
wasm-bindgen
docExpected Behavior
in version 0.2.93, the generated function signature in typescript would be
Actual Behavior
but in 0.2.95, it becomes.
Additional Context
The problem doesn't seem to be
JsError
itself, I originally run into the problem while usingserde-wasm-bindgen
and the function returnsResult<i32,JsValue>
. The generated ts function also returnsArray
as output.The text was updated successfully, but these errors were encountered: