-
Notifications
You must be signed in to change notification settings - Fork 75
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 option to generate ES Maps for protobuf map fields #1031
Comments
Hey Josephus, I can't give you an exhaustive list of popular libraries, but state management packages like Redux and frameworks like Next.js (SSR with getServerSideProps) don't support Maps yet. An option to generate maps as |
Yes, an option would be great to have. |
I took a quick-ish look at this. An option sounds easy on the surface, but this would require a new kind of option that propagates from I'm relatively sure no mechanism for communication from type descFieldMapCommon<T extends ScalarType = ScalarType> = T extends Exclude<ScalarType, ScalarType.FLOAT | ScalarType.DOUBLE | ScalarType.BYTES> ? {
readonly fieldKind: "map";
// other fields omitted...
/** Whether the generated code expects an ES6 map or a plain object. Hint for reflection code. */
es6Map: boolean;
} : never; Wiring this will mean that Even though this solution is not ideal (imho), the alternatives seem even more convoluted. It would also be possible to create options for relevant utilities (e.g. Maybe someone else has a better idea or I may have overlooked something obvious. |
Greetings!
Protobuf-ES currently generates plain JS objects for protobuf
map
fields, instead ofMap
instances. The manual mentions that this was decided for compatibility with "popular libraries":Maps have been supported by browsers and other JS runtimes for a while now (roughly since 2015), and from personal experience, seem to be widely supported across the ecosystem.
Are there any plans to revisit this decision? Alternatively, could an option be added that can be set to generate maps instead of objects? Something similar to what is available for 64-bit ints, where strings can be generated instead of bigints.
Thanks!
The text was updated successfully, but these errors were encountered: