-
Notifications
You must be signed in to change notification settings - Fork 66
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
Cannot encode field to JSON #860
Comments
Hey Ante, the optional Protobuf field compiles to: /**
* @generated from field: optional string header_image = 4;
*/
headerImage?: string; The questionmark makes the property optional, meaning that it can be omitted, or set to
In TypeScript, optional properties cannot be Can you share which ORM you are using? I'd expect |
@timostamm using typeorm and it returns |
The issue typeorm/typeorm#8703 pinpoints the problem. Unfortunately, there isn't a good resolution. I hope that it's clear that we cannot make all optional properties also accept What we can do is treat BTW, |
@timostamm yes absolutely it makes sense! Thanks for back-porting this! |
I have proto schema like:
When I try to create a instance in Typescript with:
I get this error:
I am using latest versions of following libraries to generate schema and use in Typescript project:
I noticed above is happening due to
headerImage
sometimes being passed asnull
since it can be optional in the DB. If I fallback toundefined
eg.headerImage: messageFromDb.headerImage || undefined
everything works. While this is easy for one type I have more complex type where doing aboveundefined
fallback would be inefficient and complicated.My question is why can't the library encode
null
to JSON or why does it encode it in the first place when it is marked asoptional
in the proto schema?The text was updated successfully, but these errors were encountered: