-
Notifications
You must be signed in to change notification settings - Fork 4
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
Wrapper methods in GRPCClientClient to get parameter types of the wrapped GRPC call #200
Comments
@tegefaulkes can you rewrite this issue with the new issue templates? Is this a design issue or development issue? It cannot be both. |
There still are no templates when creating a new issue. I took this one from the .github development template. |
That doesn't happen for me. Go to the GitHub issues and click new issue. You'll see it.
…On 6 July 2021 11:21:56 am AEST, Brian Botha ***@***.***> wrote:
There still are no templates when creating a new issue. I took this one
from the .github development template.
The table at the top doesn't seem to be working. Also, why is there a
name and title in it?
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#200 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
@tegefaulkes this missing type information is by design. The reason is that If we do what you are suggesting, it would require us to update the types twice everytime we changed the protobuf calls. So this is why we used the There is a possible solution using the utility types of typescript to make the types propagate properly: https://www.typescriptlang.org/docs/handbook/utility-types.html#parameterstype However I think this is not high priority unless you can figure out which one to use quickly. |
Here's an example:
Suppose we use:
The problem is that Another problem is that I don't know how to slice off the last type. So for now, we'll keep this issue in the back burner. |
Looks like there is a way: https://stackoverflow.com/questions/63789897/typescript-remove-last-element-from-parameters-tuple-currying-away-last-argum Basically we just need the remove the last parameter which is the callback. |
We would have to create our own utility type here in Note that this would have to be different for the stream calls which have different signatures. Would need to check how the protobuf works. |
Relevant to #230. @DrFacepalm I wonder if this would actually prevent us from making those signature mistakes when calling the grpc stub functions. |
@DrFacepalm has achieved this on We'll be using a |
@tegefaulkes This does also fix #230? Or will that require some changes to the tests? |
I've been looking into this and I've looked over what @DrFacepalm has done. The utility types works to a degree, but there are 2 complications with it. It seems to be pretty hard to infer the return type from the callback, I haven't found something that works for that yet. The other problem is that utility types doesn't support overloaded function definitions currently and it doesn't look like that feature will be added. So while yes, we can get the all the arguments minus the callback and infer that properly. the result is we're limited to just one of the overloaded function definitions. So at this stage I don't think there is an easy solution for this. |
The last 3 comments here microsoft/TypeScript#32164 (comment) may provide a hack for this. Can resolve this later. |
Fixes to #230 has removed the need to provide metadata and call options for most calls now. This has become low priority now. Moving it back to |
The lack of type signature propagation led to this problem: https://gitlab.com/MatrixAI/Engineering/Polykey/js-polykey/-/merge_requests/213#note_739516636. It basically involved the usage of Note that propagating the type signatures can be important all the way to the CARL retry functions if we make use of the automatic way of passing metadata or not.
It's going to require some special types to propagate this. The second parameter array must be matched up with the arguments of the lower order function, but with possibly an additional metadata. One might even need to pass relevant call options too? |
Back to do, we resolved this for now just by always using a common idiom in for |
Once we moved to JSON RPC, we no longer have this problem because we won't be using any code generation. |
That makes this Issue irrelevant now. I think we should close it. |
Specification
Here is an example of a function from src/client/GRPCClientClient.ts:39:
While the return type is explicit here as
grpcUtils.promisifyUnaryCall<clientPB.StatusMessage>
.The type information for the parameters are completely missing. What do I pass to this? is it one parameter or many?
To find out I need to go look at the definition of
this.client.vaultsCreate
We should explicitly state the parameters and their types like so:
Additional context
This is used by the CLI and the Polykey GUI to handle comunication to the agent. it will be used extensively. adding type information will make it:
As it curretly is error will only come up during runtime when calling the function.
Tasks
...args
with the respective parameter and type for each function.The text was updated successfully, but these errors were encountered: