Skip to content
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

implement OptionIntoWasmAbi for JsValue #2139

Closed
ctaggart opened this issue May 15, 2020 · 2 comments
Closed

implement OptionIntoWasmAbi for JsValue #2139

ctaggart opened this issue May 15, 2020 · 2 comments

Comments

@ctaggart
Copy link
Contributor

Motivation

On several occasions, I've want to map a parameter as Option<&JsValue> or a return type as Option<JsValue>, just to indicate explicitly that it is optional. I realize JsValue supports null & undefined.

Proposed Solution

Implement the trait.

Alternatives

I think of JsValue as the TypeScript any type. TypeScript also has the non-primitive object type that does not support null or undefined, but everything else. May be it would be better to add that so it makes more sense to have a Options<JsSome> or something like that.

@alexcrichton
Copy link
Contributor

The reason we haven't implemented this is that there's no way to distinguish between Some(null) and None in JS, so there's no way to losslessly represent the value in JS. We've currently been requiring that Rust opts-in to .unwrap_or(...) or something like that.

@ctaggart
Copy link
Contributor Author

Okay, I may revisit this again in the future with more concrete examples, after I ship the generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants