-
Notifications
You must be signed in to change notification settings - Fork 764
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
Fix missing TypeScript return type for serverStreaming
calls.
#1167
Merged
sampajano
merged 8 commits into
grpc:master
from
lukasmoellerch:ts-method-descriptor-constructor
Nov 19, 2021
Merged
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7ec3b9f
Add strongly types to MethodDescriptor constructor
lukasmoellerch 7b149dd
Replace method return types of MethodDescriptor
lukasmoellerch 5092589
Merge branch 'master' into ts-method-descriptor-constructor
sampajano 177aebc
Generate type annotations in ts mode
lukasmoellerch c20a5f5
Revert serialize / deserialize fn ts type to any
lukasmoellerch 1f49a43
Merge branch 'ts-method-descriptor-constructor' of github.com:lukasmo…
lukasmoellerch f063db0
add req / resp type, revert serialize / deserialize changes
lukasmoellerch 358f188
Revert method descriptor type annotation change
lukasmoellerch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,11 +70,11 @@ declare module "grpc-web" { | |
|
||
export class MethodDescriptor<REQ, RESP> { | ||
constructor(name: string, | ||
methodType: any, | ||
requestType: any, | ||
responseType: any, | ||
requestSerializeFn: any, | ||
responseDeserializeFn: any); | ||
methodType: string, | ||
requestType: new (...args: unknown[]) => REQ, | ||
responseType: new (...args: unknown[]) => RESP, | ||
requestSerializeFn: (request: REQ) => Uint8Array, | ||
responseDeserializeFn: (bytes: Uint8Array) => RESP); | ||
createRequest(requestMessage: REQ, | ||
metadata?: Metadata, | ||
callOptions?: CallOptions): Request<REQ, RESP>; | ||
|
@@ -83,10 +83,10 @@ declare module "grpc-web" { | |
status?: Status): UnaryResponse<REQ, RESP>; | ||
getName(): string; | ||
getMethodType(): string; | ||
getResponseMessageCtor(): any; | ||
getRequestMessageCtor(): any; | ||
getResponseDeserializeFn(): any; | ||
getRequestSerializeFn(): any; | ||
getRequestMessageCtor(): new (...args: unknown[]) => REQ; | ||
getResponseMessageCtor(): new (...args: unknown[]) => RESP; | ||
getRequestSerializeFn(): (request: REQ) => Uint8Array; | ||
getResponseDeserializeFn(): (bytes: Uint8Array) => RESP; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above :) |
||
} | ||
|
||
export class Request<REQ, RESP> { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make the return type to match the Closure type definition here? The fact it's currently using
Uint8Arry
is implementation detail and should probably be omitted.grpc-web/javascript/net/grpc/web/methoddescriptor.js
Line 32 in 1efe741
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not quite sure why it would make sense to have these typed as wither
unknown
orany
- if we allow more values here consumers will be allowed to createMethodDescriptor
instances which break internal invariants, e.g. I could create aMethodDescriptor
with a serialize function which returns a number and typescript won't complain, but during runtime it will break. In my opinionMethodDescriptor
is part of the public interface and thus the constructor should only allow valid values to be passed to the constructor. Nevertheless I can totally understand if you want it to return an interface / unknown instead, maybe it's just a matter of personal preference.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get your sentiment in general.. Although because MethodDescriptor code is generated rather than specified by callers, this probably doesn't make a practical difference..
The main reason i want to keep this in sync with the Closure type annotation is that internally (Google) we're referring to the Closure type as source of truth, and only on Github we're also adding the TS type info. And because the internal types are subject to change, I don't want us to commit to stronger types in TS than we do in JS. If that makes sense :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok sure, thanks for the explanation. I reverted the types of
requestSerializeFn
andresponseDeserializeFn
toany
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot :)