Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Generating map<K, V> on javascript type issue

未关闭
#14 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞

调研方向

从提供的 .proto map 字段和 protoc 命令开始,然后检查生成的 MessageResponse .ts AsObject 声明。使用所述的 master/v3.18 和 Node.js 设置复现输出;当生成的 map 类型和字段命名与文档所述的 JavaScript/TypeScript 预期一致时,即完成。

由索引模型根据 Issue 内容生成。

描述

bug javascript P3 triaged

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]>

主要语言
JavaScript
星标
471
派生
91
平均合并
1 天 12 小时
30 天内合并 PR
6

环境准备

我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

protocolbuffers/protobuf-javascript 的其他 Issue

查看 protocolbuffers/protobuf-javascript 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。