grpc-web: Typescript Type Check Errors
Some errors exposed when I try to compile my generated typescript code.
One error message here:
Argument of type '(request: Empty) => Uint8Array' is not assignable to parameter of type '(request: {}) => {}'.
Types of parameters 'request' and 'request' are incompatible.
Type '{}' is not assignable to type 'Empty'.
Property 'serializeBinary' is missing in type '{}'.
And I found the generation code is here: https://github.com/grpc/grpc-web/blob/86631990e365130d5cfca3aa93613ec1eeef7da4/javascript/net/grpc/web/grpc_generator.cc#L395
Another error message here:
Argument of type '(err: Error, response: Empty) => void' is not assignable to parameter of type '(err: Error, response: {}) => void'.
Types of parameters 'response' and 'response' are incompatible.
Type '{}' is not assignable to type 'Empty'.
And I found the generation code is here: https://github.com/grpc/grpc-web/blob/86631990e365130d5cfca3aa93613ec1eeef7da4/javascript/net/grpc/web/grpc_generator.cc#L438
The part of the wrong generated code shows here:
methodInfoSome = new grpcWeb.AbstractClientBase.MethodInfo(
Empty,
(request: SomeRequest) => { // Here is the first error
return request.serializeBinary();
},
Empty.deserializeBinary
);
some(
request: SomeRequest,
metadata: grpcWeb.Metadata,
callback: (err: grpcWeb.Error,
response: Empty) => void) {
return this.client_.rpcCall(
this.hostname_ +
'/SomePath',
request,
metadata,
this.methodInfoSome,
callback); // Here is the second error which the callback is `(err: Error, response: Empty) `
}
The Empty
message defined in proto file likes this message Empty {}
FYI: My TS version is 3.0.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (3 by maintainers)
I ran into this as well, and i think it is related to typescripts strict mode.
If you are interested i can probably come up with a fix and send a PR. 😃