Skip to content

missing generics in generated typescript file #375

Open
@Edregol

Description

@Edregol

Hi 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 e03f5dd 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' 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!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions