grpc-web
grpc-web copied to clipboard
Generated Typescript code is not compiling with type checking enabled
The generated typescript code for the GRPC client does not compile when the type checking is enabled.
This change Disable static checkers on generated js files added //@ts-nocheck which allows the typescript compiler starting from version 3.7 to accept the code, but with older versions (which ignore this comment option) it fails.
There are two problems in the generated code: The code calls unaryCall but this method got removed from the interface AbstractClientBase already.
Also it passes MethodInfo where MethodDescriptor is expected.
Is there a reason why it is like this? Otherwise I suggest to remove this //@ts-nocheck again and let the generator produce code which passes the type checking.
As an alternative the index.d.ts could be updated to correctly declare the methods as they are currently used.
export class AbstractClientBase {
+ /** @deprecated use thenableCall */
+ unaryCall<REQ, RESP> (
+ method: string,
+ request: REQ,
+ metadata: Metadata,
+ methodDescriptor: MethodDescriptor<REQ, RESP> | MethodInfo<REQ, RESP>
+ ): Promise<RESP>;
+
thenableCall<REQ, RESP> (
method: string,
request: REQ,
metadata: Metadata,
- methodDescriptor: MethodDescriptor<REQ, RESP>
+ methodDescriptor: MethodDescriptor<REQ, RESP> | MethodInfo<REQ, RESP>
): Promise<RESP>;
rpcCall<REQ, RESP> (
method: string,
request: REQ,
metadata: Metadata,
- methodDescriptor: MethodDescriptor<REQ, RESP>,
+ methodDescriptor: MethodDescriptor<REQ, RESP> | MethodInfo<REQ, RESP>,
callback: (err: Error, response: RESP) => void
): ClientReadableStream<RESP>;
@@ -30,7 +38,7 @@
method: string,
request: REQ,
metadata: Metadata,
- methodDescriptor: MethodDescriptor<REQ, RESP>
+ methodDescriptor: MethodDescriptor<REQ, RESP> | MethodInfo<REQ, RESP>
): ClientReadableStream<RESP>;
}
Also, am I the only one who's having trouble with importing the REQ and RESP types here?
I have the same issue
I'm hitting the same problem. Can we submit a PR with the changes suggested by @uwemaurer ? (The d.ts changes, I mean)
BTW @vladfr
Also, am I the only one who's having trouble with importing the REQ and RESP types here?
Note that REQ and RESP are generic types. See https://www.typescriptlang.org/docs/handbook/generics.html for a full explanation. T and U in that doc would be REQ and RESP here.
Quick check — Does the sme issue still remain for anyone? :)