protocolbuffers / protocolbuffers/protobuf-javascript

Generating map<K, V> on javascript type issue

Open
#14 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug javascript P3 triaged
Dominant language
JavaScript
Stars
471
Forks
91
Avg merge
3h 57m
Merged PRs (30d)
2

Description

What version of protobuf and what language are you using?
Version: master/v3.18
Language: Javascript

What operating system (Linux, Windows, ...) and version? Linux

What runtime / compiler are you using (e.g., python version or gcc version) Nodejs

What did you do?
Steps to reproduce the behavior:

  1. Trying to export type map<K, V> so I created a proto file like this:
message MessageResponse {
  string _id = 1;
  string title = 2;
  bool disabled = 3;
  map<string,string> metadata = 4;
}
  1. Converting it using this some commands like this:
protoc -I=/libraries/protos/ /libraries/protos/src/*.proto /libraries/protos/src/**/*.proto --plugin=/libraries/protos/binaries/linux/protoc-gen-grpc-web --js_out=import_style=commonjs,binary:/libraries/protos/build/typescript --grpc-web_out=import_style=typescript,mode=grpcwebtext:/libraries/protos/build/typescript --experimental_allow_proto3_optional
  1. What I am getting on .ts files is something like:
export namespace MessageResponse {
  export type AsObject = {
    id: string,
    title: string,
    disabled: boolean,
    metadataMap: Array<[string, string]>,
  }
}
  1. Well we can see there is a suffix called Map added to my field name! also the generated type is Array<[string, string]>. but what we were expecting, based on language guide here, where an object of {"k": v, …}, like Record<string, V>

What did you expect to see
An object like: Record<string, string>

What did you see instead?
Array<[string, string]>

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the provided .proto map field and protoc command, then inspect the generated MessageResponse .ts AsObject declaration. Reproduce the output with the stated master/v3.18 and Node.js setup; done when the generated map type and field naming match the documented JavaScript/TypeScript expectation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, typescript
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.