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

Add a feature for wasm to allow HashMap<K, V> -> Map<K,V> #13

Closed
abhinavdev24 opened this issue Nov 8, 2022 · 3 comments
Closed

Add a feature for wasm to allow HashMap<K, V> -> Map<K,V> #13

abhinavdev24 opened this issue Nov 8, 2022 · 3 comments

Comments

@abhinavdev24
Copy link

When using wasm HashMap gets converted to Map but this crate is generating Record from HashMap
Eg
pub input: HashMap<String, String>

is getting converted to
input: Record<string, string>;

instead of
input: Map<string, string>;

Can we add a feature to add support for wasm?
I can raise a PR if you approve

@dbeckwith
Copy link
Owner

The goal of this library is to generate Typescript types describing the JSON serialization of Rust types. Essentially, if you take a Rust value, convert it to a JSON string using serde, and then call JSON.parse on the string in Typescript, the types generated by this library should describe the value returned by JSON.parse. JSON.parse by default parses JSON objects as plain Javascript objects, not Maps, so using the Map type does not make sense unless you have another layer of code that converts JS objects to Maps. That doesn't fit within the goal of this library which I'm trying to keep relatively simple. This was also brought up in #11.

If you could share more about your use case, maybe I could provide some advice on how to get the types you're looking for?

@abhinavdev24
Copy link
Author

We are trying to be compatible with serde_wasm_bindgen which by default converts HashMap to Map

@dbeckwith
Copy link
Owner

I would say in general that it's outside of the current scope of this library to support the default serialization behavior of serde_wasm_bindgen which uses Map and undefined. However, it looks like you can use Serializer::json_compatible() to make it produce JSON types, which would then be compatible with this library. If you don't want to change how serde_wasm_bindgen is serializing data, I would suggest finding a different library for generating Typescript types for now. It's possible I'll add support for this sometime in the future, but for now I'd like to keep this library simple and only target JSON.

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

No branches or pull requests

2 participants