Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated typescript source has type incompatible error #545

Closed
developerlaoz opened this issue Apr 26, 2019 · 3 comments
Closed

Generated typescript source has type incompatible error #545

developerlaoz opened this issue Apr 26, 2019 · 3 comments

Comments

@developerlaoz
Copy link

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);
   }
 }
@jcramb
Copy link

jcramb commented May 7, 2019

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

@stanley-cheung
Copy link
Collaborator

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

@stanley-cheung
Copy link
Collaborator

Should be fixed in 1.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants