Skip to content
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

(Typescript) Mark some metadata parameters as optional #1369

Merged
merged 2 commits into from
Oct 16, 2023

Conversation

andrewmbenton
Copy link
Contributor

@andrewmbenton andrewmbenton commented Oct 5, 2023

There are a couple of method signatures in the generated TypeScript client that should mark the metadata parameter as optional, to reduce explicitly passing unnecessary null values:

printer->Print(vars,
"request: $input_type$,\n"
"metadata: grpcWeb.Metadata | null): "
"$promise$<$output_type$>;\n\n");

printer->Print(vars,
"request: $input_type$,\n"
"metadata: grpcWeb.Metadata | null,\n"
"callback?: (err: grpcWeb.RpcError,\n"
" response: $output_type$) => void) {\n");

Making the metadata parameter optional in the method returning a Promise would bring the TypeScript client closer in line with the PromiseClient interface available when generating with import_style=commonjs+dts.

Resolves #1368

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Oct 5, 2023

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link
Collaborator

@sampajano sampajano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrewmbenton Thanks so much for this change (and sorry for the delay)! This makes a lot of sense! 😃

Just one comment! Will merge once it's addressed/acked, and when tests passes!

Thanks again for the contribution! :)

@@ -671,7 +671,7 @@ void PrintTypescriptFile(Printer* printer, const FileDescriptor* file,
printer->Indent();
printer->Print(vars,
"request: $input_type$,\n"
"metadata: grpcWeb.Metadata | null,\n"
"metadata?: grpcWeb.Metadata | null,\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've mentioned this in the associated issue (which i copied to this PR too :))

Making these parameters optional I believe would bring the TypeScript client closer in line with the PromiseClient interface available when generating with import_style=commonjs+dts.

I believe this is true for the other change! But not this one.

It seems that callback? has only 1 occurrence the whole file, and is a unique feature in TS codegen :)

I don't mind this change also, but maybe you could consider rewording your comment (and PR description now :)) to note that it only applies to the other change? Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will reword my comments. You are right that the PromiseClient generated with import_style=commonjs+dts doesn't seem to have any generated methods with a callback parameter.

For true parity with the PromiseClient I would remove the null from the metadata param's type, but that would break user code that passes null so I didn't propose that change.

I am also happy to revert the change to the function that doesn't return a Promise if that's preferable.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For true parity with the PromiseClient I would remove the null from the metadata param's type, but that would break user code that passes null so I didn't propose that change.

Definitely! Appreciate the caution and i'd agree!

I am also happy to revert the change to the function that doesn't return a Promise if that's preferable.

Yeah i think that's an option but i don't see this making things more inconsistent than they already were (at least my glimpse of it) so i think this is still a good thing to keep 😃

Thanks for offering tho!

Copy link
Collaborator

@sampajano sampajano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks so much for the change again! Much appreciated!

@sampajano sampajano enabled auto-merge (squash) October 16, 2023 21:25
@sampajano sampajano merged commit 1ab0bdc into grpc:master Oct 16, 2023
3 checks passed
@andrewmbenton andrewmbenton deleted the patch-1 branch October 20, 2023 16:24
@sampajano sampajano changed the title feat(typescript): mark some metadata parameters as optional (Typescript) Mark some metadata parameters as optional Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypeScript client method signatures should mark metadata as optional
3 participants