grpc-web icon indicating copy to clipboard operation
grpc-web copied to clipboard

Generated Typescript code is not compiling with type checking enabled

Open uwemaurer opened this issue 5 years ago • 4 comments

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>;
   }

uwemaurer avatar Aug 31 '20 15:08 uwemaurer

Also, am I the only one who's having trouble with importing the REQ and RESP types here?

vladfr avatar Nov 01 '20 14:11 vladfr

I have the same issue

dvabuzyarov avatar Nov 02 '20 14:11 dvabuzyarov

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.

acalvo avatar Dec 02 '20 12:12 acalvo

Quick check — Does the sme issue still remain for anyone? :)

sampajano avatar Jun 25 '24 04:06 sampajano