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

Avoid unused definition imports from proto-loader #1826

Merged
merged 2 commits into from
Jun 23, 2021

Conversation

mtlewis
Copy link
Contributor

@mtlewis mtlewis commented Jun 23, 2021

Since proto files don't always contain enums and messages, it was possible to get into a state where generated code contained unused imports which caused TS errors. This change makes those imports conditional on the existence of the corresponding definitions in the proto file.

Co-authored-by: Austin Puri austin.puri@gmail.com
Co-authored-by: Joe Porpeglia josephp@spotify.com

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Jun 23, 2021

CLA Signed

The committers are authorized under a signed CLA.

Since proto files don't always contain all types of definition, it was
possible to get into a state where generated code contained unused
imports which caused TS errors. This change makes those imports
conditional on the existence of the corresponding definitions in the
proto file.

Co-authored-by: Austin Puri <austin.puri@gmail.com>
Co-authored-by: Joe Porpeglia <josephp@spotify.com>
Signed-off-by: Mike Lewis <mtlewis@users.noreply.github.com>
@mtlewis mtlewis force-pushed the conditional-definition-imports branch from 71d08ba to f289c34 Compare June 23, 2021 15:46
@@ -617,7 +645,7 @@ function generateLoadedDefinitionTypes(formatter: TextFormatter, namespace: Prot

function generateRootFile(formatter: TextFormatter, root: Protobuf.Root, options: GeneratorOptions) {
formatter.writeLine(`import type * as grpc from '${options.grpcLib}';`);
formatter.writeLine("import type { ServiceDefinition, EnumTypeDefinition, MessageTypeDefinition } from '@grpc/proto-loader';");
Copy link
Contributor Author

@mtlewis mtlewis Jun 23, 2021

Choose a reason for hiding this comment

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

Note that the ServiceDefinition import in the old version of the line appears to always be unused in the generated code.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I think it became unused in #1745.

@murgatroid99
Copy link
Member

The change looks good. Please run npm run generate-golden to update the golden files.

Signed-off-by: Mike Lewis <mtlewis@users.noreply.github.com>
Copy link
Member

@murgatroid99 murgatroid99 left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution

@murgatroid99 murgatroid99 merged commit 1293b3c into grpc:master Jun 23, 2021
@murgatroid99
Copy link
Member

This has been published in version 0.6.3.

@mtlewis mtlewis deleted the conditional-definition-imports branch June 24, 2021 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants