grpc-web
grpc-web copied to clipboard
missing symbol $ in get/set functions in TypeScript output of grpc-web
If I define a proto message with a field named "myField" then protoc generates the functions getMyfield() and setMyfield() for the related object.
What happens, if my field name is "extension"? protoc generates the functions getExtension$() and setExtension$(), it adds a $ since the functions getExtension() and setExtension() are already defined by jspb.Message for the extension api of protobuf.
grpc-web doesn't recognize this, the created TypeScript output contains getExtension() and setExtension() without the $. This causes a TypeScript compiler error, if you just change the generated d.ts files by adding the $ to the related functions then everything works as expected.
I just ran across this issue, one of my messages has a field called extension
To reproduce:
syntax = "proto3";
message TestMessage {
int32 extension = 1;
}
then run
protoc -I . --js_out=import_style=commonjs,binary:. --grpc-web_out=import_style=commonjs+dts:. *.proto
Check the .js and .d.ts and notice proto.TestMessage.prototype.setExtension$ in the .js and getExtension(): number; in the .d.ts
Here's the relevant code in the js protoc compiler: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/compiler/js/js_generator.cc#L544
On master, it is now line 524: https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/compiler/js/js_generator.cc#L524
Any update on this here?
For some reason google removed js compilation from protoc and now it's a plugin:
https://github.com/protocolbuffers/protobuf-javascript/blob/main/generator/js_generator.cc#L525
Putting it here so when they reorg it again in 2 weeks we won't need to go down the rabbit hole
if (name == "Extension" || name == "JsPbMessageId") {
// Avoid conflicts with base-class names.
name += "$";
}