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

Feat: proto map generates a Hashmap instead of an object #547

Closed
jay-babu opened this issue Apr 8, 2022 · 2 comments · Fixed by #686
Closed

Feat: proto map generates a Hashmap instead of an object #547

jay-babu opened this issue Apr 8, 2022 · 2 comments · Fixed by #686

Comments

@jay-babu
Copy link

jay-babu commented Apr 8, 2022

currently,

map<uint32, X> x = 2; in proto outputs { [key: number]: X }.

What are your thoughts of it generating a HashMap instead?

@stephenh
Copy link
Owner

stephenh commented Apr 8, 2022

I dunno, not 100% against it, but I think the existing output is ~slightly more idiomatic JS/TS where "maps" are, IMO anyways, almost always just objects with keys and not the actual Map instances.

If you want to add an option for it, that seems fine; I'm a little concerned about having two types of map output being a little tedious in the code, but I'd merge a PR if you put one together.

Thanks!

moznion added a commit to moznion/ts-proto that referenced this issue Oct 15, 2022
This option controls the way to generate the code for protobuf's
`map<key_type, value_type>`:

- true: it generates the code with using JavaScript Map type like `Map<key_type, value_type>`
- false (default): it generates the code with key-value pair like `{[key: key_type]: value_type}`

This fixes stephenh#547

Signed-off-by: moznion <moznion@mail.moznion.net>
stephenh pushed a commit that referenced this issue Oct 16, 2022
This option controls the way to generate the code for protobuf's
`map<key_type, value_type>`:

- true: it generates the code with using JavaScript Map type like `Map<key_type, value_type>`
- false (default): it generates the code with key-value pair like `{[key: key_type]: value_type}`

This fixes #547

Signed-off-by: moznion <moznion@mail.moznion.net>

Signed-off-by: moznion <moznion@mail.moznion.net>
@stephenh
Copy link
Owner

This was just fixed in #686 and will be in a release soon; thanks @moznion !

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

Successfully merging a pull request may close this issue.

2 participants