-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
getter for oneof field not returning value of field; returns name of field #96
Comments
While we're in there, this (especially "none" to mark field 0) may be problematic:
This contrived message produces this code:
Probably want to reengineer without a string name, or use a name that is not legal as a message field name. |
Ah... after further review, I think I see what's happened. Per original #96 (comment) above, the getter should return the value of the supplied oneof field. |
Hmm, all of this makes sense. Would like to send a PR for this? |
I'm not familiar with your code-base; but if you point me to a likely file, I'll do the code/test/PR ... ... Ok, i looked into descripter.js & createOneofGetter()... So: if there's a developer's guide (explaining the proto factory code-generator and conventions) the maybe I could be useful... but it would be quickly/easily |
Hey @jackpunt. sorry, I missed this. Actually, you don’t need to worry about bazel. just invoke The right place for this is to create an AST generator function named createOneOfWhichGetter and copy the contents of the createOneofGetter func and change it in a way that would generate the AST mentioned above. There is a PR #94 to migrate the project to TypeScript which I'd like to see land so that people can contribute easily. |
I just had time to take a look at this. and I realized that protoc-gen-ts does the right thing here. builtin js does not generate a union getter that gives you the value. instead, it just gives you a discriminator getter and that's it. |
Ok. I see what you're saying; The other languages distinguish between msg.getValue() and msg.getValueType: The method returns the string discriminator [rather than the actual one-of Since you have done the awesomeness of defining get methods for the fields
although: since the protoc-gen-ts code has all the type info, The other issue is still there: Also: with tsc 4.3+, my tsconfig.json says: |
Breath some life into this... B) It is really important to change the implementation of the discriminator to not use "none" as a string value. |
Sahin, sorry to be late getting to this, I've been off for the summer.
(I commented on the closed #53 (or #39 ?) but am unsure how to re-open at this point)
It seems that the oneof getter (or computeOneofCase ?) needs a bit more work; consider:
I believe it should be the case that:
That is: the type of TypedValue.value should be: number | string | boolean
rather than the slot name: "intValue" | "strValue" | "boolValue" | "none"
Conceptually an extra dereference [but maybe not this ugly]:
(happy to help, if you point me to the relevant code)
After further review (28-Oct; see #96 (comment) below, about "none"),
I suspect the generated code could be something like:
The text was updated successfully, but these errors were encountered: