Generate alternate accessor for fields with presence
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- backend
调研方向
通过生成所示的 OptTest 消息并调用 toObject,重现可选字段的情况。先从生成的 toObject 代码和 getFieldWithDefault 调用入手;确定 presence 应如何影响默认值。完成标准是:未设置的可选字段产生 undefined,而不是 0 或空字符串,并且为所示的 proto 提供覆盖。
由索引模型根据 Issue 内容生成。
描述
When I executed the toObject method on a message with a field marked optional, that field became the default value like 0 or "". I expect it would be undefined.
I guess it is because the third argument of getFieldWithDefault is not undefined.
Since proto3 currently support optional keyword, when optional is specified, I think it should be undefined if it is not given.
proto
syntax = "proto3";
package com.book;
message OptTest {
optional string name = 1;
}
generated toObject code
proto.com.book.OptTest.toObject = function(includeInstance, msg) {
var f, obj = {
name: jspb.Message.getFieldWithDefault(msg, 1, "")
};
if (includeInstance) {
obj.$jspbMessageInstance = msg;
}
return obj;
};
versions
$ npm list --depth=0 -g
/usr/local/lib
+-- google-protobuf@3.21.2
+-- grpc_tools_node_protoc_ts@5.3.3
`-- grpc-tools@1.12.4
- 主要语言
- JavaScript
- 星标
- 471
- 派生
- 91
- 平均合并
- 3 小时 57 分钟
- 30 天内合并 PR
- 2
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
protocolbuffers/protobuf-javascript 的其他 Issue
-
难度 5/5 一周以上 新手友好度 25/100
-
难度 5/5 一周以上 新手友好度 30/100
protocolbuffers/protobuf-javascript#248 · 1 条评论 · 13 个 reaction ·
-
question
难度 3/5 1-2 天 新手友好度 45/100
protocolbuffers/protobuf-javascript#222 · 9 条评论 ·
-
enhancement port-fix triaged
难度 4/5 3-5 天 新手友好度 35/100
protocolbuffers/protobuf-javascript#185 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 35/100
查看 protocolbuffers/protobuf-javascript 的全部 Issue
相似的 Issue
-
code-quality refactoring
难度 2/5 1-3 小时 新手友好度 84/100
github/gh-aw-firewall#8816 ·
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
难度 2/5 1-3 小时 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
optimization optimization:agents-md-curator
难度 2/5 1-3 小时 新手友好度 86/100
githubnext/gh-aw-cao#13143 ·
-
status: needs triage
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 88/100