missing generics in generated typescript file
See original GitHub issueHi there,
first of all, I am working on a windows machine. I got the latest precompiled version of the protoc for windows found on https://github.com/protocolbuffers/protobuf/releases/tag/v3.6.1
I’ve checked out the grpc-web version https://github.com/grpc/grpc-web/commit/e03f5ddb63cc872224167897f20af71047b6cb8e and compiled the protoc-gen-grpc-web plugin with bazel myself.
My proto file looks like ths:
service TestProto {
rpc getTest(TestRequest) returns (TestReply) {}
rpc getTestStream(TestRequest) returns (stream TestReply) {}
}
message TestRequest {
int32 id = 1;
}
message TestReply {
string reply = 1;
}
I am using the npm packages “grpc-web”: “1.0.2” and “google-protobuf”: “3.6.1” Now I compile the proto file with :
protoc --proto_path="$protoFilePath/" --js_out="import_style=commonjs:$CurrentOutDir" --grpc-web_out="import_style=commonjs+dts,mode=grpcwebtext:$CurrentOutDir" $protoFile
The following methods will be generated:
getTest(
request: TestRequest,
metadata: grpcWeb.Metadata,
callback: (err: grpcWeb.Error,
response: TestReply) => void
): grpcWeb.ClientReadableStream;
getTestStream(
request: TestRequest,
metadata: grpcWeb.Metadata
): grpcWeb.ClientReadableStream;
Which gets me a compiler error Generic type ‘ClientReadableStream<Response>’ requires 1 type argument(s). Manually correcting this to grpcWeb.ClientReadableStream<TestReply>
solves the issue and renders the code functional again.
There is similar behavior when setting the output to--grpc-web_out="import_style=typescript
Which generates the following method:
getTestStream(
request: TestRequest,
metadata: grpcWeb.Metadata) {
return this.client_.serverStreaming(
this.hostname_ +
'/TestProto/getTestStream',
request,
metadata,
this.methodInfogetTestStream);
}
This gets me this compiler error Argument of type ‘TestRequest’ is not assignable to parameter of type ‘Request’. Property ‘cache’ is missing in type ‘TestRequest’
In order to make this work again I had to update index.d.ts in the grpc-web npm package which exports the following:
export class AbstractClientBase {
rpcCall<Request, Response> [...]
serverStreaming [...]
since serverStreaming doesn’t have any generics defined, a wrong type for Request is assumed. Adding the generic to the serverStreaming method makes everything work again.
export class AbstractClientBase {
[...]
serverStreaming<Request, Response> [...]
I guess this is a bug, or is there anything that I did wrong?
Thanks in advance!
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:11 (3 by maintainers)
I have encountered this as well. protoc --version libprotoc 3.6.1 protoc-gen-grpc-web 1.0.3 grpc-web: ^1.0.3
Error message from tsc
nevermind, was able to resolve my issue by opting for
--grpc-web_out=import_style=commonjs+dts
instead of--grpc-web_out=import_style=typescript