-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Update TypeScript default values for proto3 syntax #743
Conversation
Optional fields can in fact be
Let's say you are creating a message from a plain object that has undefined or null values, then it would just copy these over, effectively setting field values to explicit undefined or null implicitly. Basically, interoperability with plain objects comes at this cost here. |
How about changing it to Shouldn't be left as |
Just to clarify, if i have a proto3 file like so:
And i create a message of
Would |
Generated TypeScript definitions evaluate
If you explicitly This stuff clearly became too complex, hrm. |
|
The correct test here is
This is more a limitation of using a dynamically typed language like javascript plus having the option to simply use plain objects. Definitions use |
Wouldn't it be possible to, if the message is proto3, check if the |
Isn't the only difference with proto3 in this regard that all fields are optional? Iirc proto2 optional fields exhibit the same behavior, no matter the syntax - or am I wrong?
In a dynamic language, you have to deal with different types. Even when using TypeScript, What I am trying to do now is to pave the way to remove the |
…ment message fields as non-optional where applicable (ideally used with TS & strictNullChecks), see #743
This now explicitly types all message fields as non-optional, except for optional messages which are explicitly typed as This should work because constructors and |
Yup, this is exactly what I intended! Thanks for taking the time to fix it 😄 |
This update correctly handles proto3 default value typings
Changes: