Grpc-web: TypeScript type generation wrong when using multiple files

Created on 10 Dec 2019  Â·  4Comments  Â·  Source: grpc/grpc-web

I'm currently migrating my GRPC service declarations from JS to Typescript and noticed that the code generation is wrong when referencing messages/types from other files.

Given the code below, the following MyServiceServiceClientPb.ts is generated:

...
  methodInfoaddOne = new grpcWeb.AbstractClientBase.MethodInfo(
    MyMessagesFile_pbInteger,
    (request: MyMessagesFile_pbInteger) => {
      return request.serializeBinary();
    },
    MyMessagesFile_pbInteger.deserializeBinary
  );
...

Note the correct type is MyMessagesFile_pb.Integer (the dot is missing)!

This is printed in grpc_generator.cc:713.


Using libprotoc 3.11.1 and grpc-web 1.0.7

MyServiceFile.proto

syntax = "proto3";
import "MyMessagesFile.proto";

service MyService {
  rpc addOne(Integer) returns (Integer);
}

MyMessagesFile.proto

message Integer {
  int32 number = 1;
}

package.json

{
  ...
  "scripts": {
    ...
    "grpc-generate": "mkdir -p src/proto && protoc -I=/path/to/proto/folder /path/to/proto/folder/*.proto --js_out=import_style=commonjs:src/proto --grpc-web_out=import_style=typescript,mode=grpcwebtext:src/proto && for f in src/proto/*.js; do sed -i '1s;^;/* eslint-disable */;' $f; done",
    "grpc-generate-macos": "mkdir -p src/proto && protoc -I=/path/to/proto/folder /path/to/proto/folder/*.proto --js_out=import_style=commonjs:src/proto --grpc-web_out=import_style=typescript,mode=grpcwebtext:src/proto && for f in src/proto/*.js; do sed -i '' '1s;^;/* eslint-disable */;' $f; done",
    ...
  }
  ...
}

Most helpful comment

Affecting me too... can you share your sed expression @Jdban?

Sure, it's not very generic though. It's just doing an explicit find/replace on the string in all the .ts files.

in our bash script:

# Handles this annoying bug: https://github.com/grpc/grpc-web/issues/693
ORIGINAL=shared_pbFilterRequest
REPLACEMENT=shared_pb.FilterRequest
grep -l -E "$ORIGINAL" **/*.ts  | xargs sed -i.bak "s#$ORIGINAL#$REPLACEMENT#g"
rm -rf js/*.bak   # Our files are in a js folder

All 4 comments

This is happening to us too. Extremely annoying... I guess I'm fixing it with sed for now?

That’s how I’m approaching it. Since I don’t generate the files too often, and I don’t have that many, it’s not too bad to do it.

Fixing it does not look too hard, but I don’t have the bandwidth to tackle it at the moment.

If you end up creating a generic-enough script to use as workaround, please post it here for everyone. :)

João

On 12 Feb 2020, at 04:40, Jason Banich notifications@github.com wrote:


This is happening to us too. Extremely annoying... I guess I'm fixing it with sed for now?

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.

This is happening to us too. Extremely annoying... I guess I'm fixing it with sed for now?

Affecting me too... can you share your sed expression @Jdban?

Affecting me too... can you share your sed expression @Jdban?

Sure, it's not very generic though. It's just doing an explicit find/replace on the string in all the .ts files.

in our bash script:

# Handles this annoying bug: https://github.com/grpc/grpc-web/issues/693
ORIGINAL=shared_pbFilterRequest
REPLACEMENT=shared_pb.FilterRequest
grep -l -E "$ORIGINAL" **/*.ts  | xargs sed -i.bak "s#$ORIGINAL#$REPLACEMENT#g"
rm -rf js/*.bak   # Our files are in a js folder
Was this page helpful?
0 / 5 - 0 ratings

Related issues

graup picture graup  Â·  4Comments

jmzwcn picture jmzwcn  Â·  6Comments

barrymichaeldoyle picture barrymichaeldoyle  Â·  4Comments

rwlincoln picture rwlincoln  Â·  6Comments

verihelp-vaibhav picture verihelp-vaibhav  Â·  5Comments