-
Notifications
You must be signed in to change notification settings - Fork 345
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
Compilation error for nested repeated fields with useOptionals=all
#1112
Labels
Comments
vecerek
added a commit
to vecerek/ts-proto
that referenced
this issue
Sep 29, 2024
…ll (stephenh#1112) The TS code generated for the following protobuf code with the `useOptionals=all` parameter does not compile. ```proto syntax = "proto3"; import "google/protobuf/wrappers.proto"; message NestedList { repeated google.protobuf.StringValue a_string = 1; } message Example { NestedList list = 1; } ``` The problem lies in the `decode` function not taking into account that the `value` after decoding could also be `undefined`. Therefore the following generated line: ```ts message.aString!.push(StringValue.decode(reader, reader.uint32()).value); ``` results in the following TS compilation error: ``` Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'.ts(2345) ``` The fix is to push the decoded element to the array only if it's a truthy value.
vecerek
added a commit
to vecerek/ts-proto
that referenced
this issue
Sep 29, 2024
…ll (stephenh#1112) The TS code generated for the following protobuf code with the `useOptionals=all` parameter does not compile. ```proto syntax = "proto3"; import "google/protobuf/wrappers.proto"; message NestedList { repeated google.protobuf.StringValue a_string = 1; } message Example { NestedList list = 1; } ``` The problem lies in the `decode` function not taking into account that the `value` after decoding could also be `undefined`. Therefore the following generated line: ```ts message.aString!.push(StringValue.decode(reader, reader.uint32()).value); ``` results in the following TS compilation error: ``` Argument of type 'string | undefined' is not assignable to parameter of type 'string'. Type 'undefined' is not assignable to type 'string'.ts(2345) ``` The fix is to push the decoded element to the array only if it's not an `undefined` value.
🎉 This issue has been resolved in version 2.2.1 🎉 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
The TS code generated for the following protobuf code with the
useOptionals=all
parameter does not compile.The problem lies in the
decode
function not taking into account that thevalue
after decoding could also beundefined
. Therefore the following generated line:results in the following TS compilation error:
The text was updated successfully, but these errors were encountered: