Conversation
… from src/descriptor.ts and src/field.ts
…user assigns them explicitly
… default value of '0' rather than empty string - at least that is how Google's implementation works
…f getField() calls
|
Additional tests have been added, and I made a few further corrections to the @thesayyn, please review the pull request when you have some time. Should a rework be needed, I will probably be able to do the rework next week. |
thesayyn
left a comment
There was a problem hiding this comment.
It looks way better now. but I'd prefer to have presence fields as getter instead of method.
Also, why do we need clear methods? is it part of the spec? If not, how is it different from setting the field to undefined?
src/compiler/plugin.ts
Outdated
| set patch(value: number) { | ||
| pb_1.Message.setField(this, 3, value); | ||
| } | ||
| clear_patch() { |
There was a problem hiding this comment.
I wasn't aware that we needed this. How's this any different than setting patch = undefined?
There was a problem hiding this comment.
This is an internal project file, and the whole project seems to be compiling from typescript to javascript without strictNullChecks option of tsc enabled. So I guess the clear_patch() method is really unnecessary here.
On the other hand, for users of protoc-gen-ts who have the strictNullChecks option enabled in their projects the existence of the clear_property() methods makes sense. With strictNullChecks enabled the tsc compiler will not allow the assignment of undefined, like patch = undefined in this example, simply because the setter accepts a value of some specific type other than undefined (a number in this example.)
I changed the Forgetting the
I think the so I guess to really make the setter accept As mentioned in an earlier comment, that would only be important for protoc-gen-ts users who have I kept the clear methods for now, but I can remove them (and change setters signatures) if you insist. |
That's actually what issue #80 is about. if a field is optional, then you should be able to set it to undefined. That's why i am opposed to adding the clear methods. Maybe we keep it out of this PR and handle it with another PR? |
|
Amazing work so far @tomasz-szypenbejl-td |
Alright, I will remove the clear methods so that this pull request can be merged.
Thank you. |
|
I removed the clear methods. @thesayyn please take a look - if there is anything that still needs to be fixed, just let me know. |
thesayyn
left a comment
There was a problem hiding this comment.
awesome. just @deprecated annotations are missing for has getters are belongs to a deprecated field.
…named hasPresenceFunctions -> hasPresenceGetter
Thank you. I have to give credit to @Yurzel. He did most of the hard work writing the code using Thank you for approving and merging this pull request :) |
Ah I probably should have mentioned this tool: |
|
@thesayyn any chance for the release, please? Will be much appreciated! |
This pull request is a new attempt to add field presence/absence indicators, and to optimize the serialization code. It mostly contains @Yurzel's commits from #136.
Additionally this pull request alters the generated
toObject()methods so that the returned objects contain default values.I would still like to write some additional tests to make sure that serialization really works as expected with regard to skipping fields that are OK to be skipped (i.e. unset fields for proto2 and defaults for proto3). Thus I am creating this as a draft for now. I should be able to complete work on this on Friday (2022-06-17), but it may take more time if some unexpected difficulties arise.