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

fix: use correct imports for optional fields #904

Merged
merged 1 commit into from
Aug 16, 2023
Merged

Conversation

andrehp
Copy link
Contributor

@andrehp andrehp commented Aug 16, 2023

It seems that the ts-poet.Code.toString() changes the struct and it was causing the code gen to fail to use the correct imports in some situations.

Added a struct which was failing to compile before the fix.

This should fix #896

It seems that the ts-poet.Code.toString() changes the struct and it was causing
the code gen to fail to use the correct imports in some situations.

Added a struct which was failing to compile before the fix.
@@ -873,9 +873,6 @@ function generateInterfaceDeclaration(
const name = maybeSnakeToCamel(fieldDesc.name, options);
const isOptional = isOptionalProperty(fieldDesc, messageDesc.options, options);
const type = toTypeName(ctx, messageDesc, fieldDesc, isOptional);
if (isOptional && !type.toString().includes("undefined")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The definitive fix probably lays within ts-poet, I believe the toString method shouldn't have any side-effects

Copy link
Owner

Choose a reason for hiding this comment

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

Wow, I agree that is very strange that toString has side-effects. Also kinda funny this console.warn was just hanging out here 🤷 . Thanks for finding! I'll see if I can poke around at the ts-poet root cause at some point...

Copy link
Owner

@stephenh stephenh left a comment

Choose a reason for hiding this comment

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

Ah great, thanks @andrewparmet !

@@ -873,9 +873,6 @@ function generateInterfaceDeclaration(
const name = maybeSnakeToCamel(fieldDesc.name, options);
const isOptional = isOptionalProperty(fieldDesc, messageDesc.options, options);
const type = toTypeName(ctx, messageDesc, fieldDesc, isOptional);
if (isOptional && !type.toString().includes("undefined")) {
Copy link
Owner

Choose a reason for hiding this comment

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

Wow, I agree that is very strange that toString has side-effects. Also kinda funny this console.warn was just hanging out here 🤷 . Thanks for finding! I'll see if I can poke around at the ts-poet root cause at some point...

@stephenh stephenh merged commit fa13ec7 into stephenh:main Aug 16, 2023
7 checks passed
stephenh pushed a commit that referenced this pull request Aug 16, 2023
## [1.156.6](v1.156.5...v1.156.6) (2023-08-16)

### Bug Fixes

* use correct imports for optional fields ([#904](#904)) ([fa13ec7](fa13ec7))
@stephenh
Copy link
Owner

🎉 This PR is included in version 1.156.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TS error if .proto file has the same message name as imported
2 participants