Grpc-web: Generated typescript source has type incompatible error

Created on 26 Apr 2019  路  3Comments  路  Source: grpc/grpc-web

Problem detail

The generated typescript source of responseDeserializeFn in GetUserResponse is
deserializeBinary(bytes: Uint8Array): GetUserResponse;

But the responseDeserializeFn function in AbstractClientBase.MethodInfo is
responseDeserializeFn: (bytes: {}) => Response);

bytes:Uint8Array against the bytes: {}

grpc-web version is 1.0.4
typescript version is 3.4.5


error message

Argument of type '(bytes: Uint8Array) => GetUserResponse' is not assignable to parameter of type '(bytes: {}) => GetUserResponse'.
  Types of parameters 'bytes' and 'bytes' are incompatible.
    Type '{}' is missing the following properties from type 'Uint8Array': BYTES_PER_ELEMENT, buffer, byteLength, byteOffset, and 26 more.

proto file

syntax = "proto3";

package xxx;

service Account {
  rpc GetUser (GetUserRequest) returns (GetUserResponse);
}

message GetUserRequest {
  string uid = 1;
}

message GetUserResponse {
  string uid = 1;
  string uname = 2;
}

generate command

protoc --proto_path=${PROTOCOL_FILE_DIR} ${PROTOCOL_FILE_DIR}/${PROTOCOL_FILE} \
    --grpc-web_out=import_style=typescript,mode=grpcweb:${CLIENT_OUTDIR}

AccountServiceClientPb.ts

```
...
methodInfoGetUser = new grpcWeb.AbstractClientBase.MethodInfo(
GetUserResponse,
(request: GetUserRequest) => {
return request.serializeBinary();
},
GetUserResponse.deserializeBinary
);
...

**account_pb.d.ts**

export class GetUserResponse extends jspb.Message {
getUid(): string;
setUid(value: string): void;

getUname(): string;
setUname(value: string): void;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): GetUserResponse.AsObject;
static toObject(includeInstance: boolean, msg: GetUserResponse): GetUserResponse.AsObject;
static serializeBinaryToWriter(message: GetUserResponse, writer: jspb.BinaryWriter): void;
static deserializeBinary(bytes: Uint8Array): GetUserResponse;
static deserializeBinaryFromReader(message: GetUserResponse, reader: jspb.BinaryReader): GetUserResponse;
}

**dts file of grpc-web**

 ```
 export namespace AbstractClientBase {
    class MethodInfo<Request, Response> {
      constructor (responseType: new () => Response,
                   requestSerializeFn: (request: Request) => {},
                   responseDeserializeFn: (bytes: {}) => Response);
    }
  }

Most helpful comment

This should be fixed in #540. Let's wait for the next release.

All 3 comments

Encountering a similar error - any word on how to fix this?

This should be fixed in #540. Let's wait for the next release.

Should be fixed in 1.0.5

Was this page helpful?
0 / 5 - 0 ratings