You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The responseSerialize is typed to "any", but Value.encode expects the value to be a "Value" object.
Same thing, responseDeserialize will return a "Value" object, but the end user probably expects a plain object instead.
As a result, when reading the result of a call to readVariable, the end user needs to manually call Value.unwrap.
The code looks like this:
const value = Value.unwrap(await client.readVariable({ /*...*/ });
Same thing server-side where we need to manually call Value.wrap.
I believe the correct implementation should generate something like:
First of all, thanks a ton for ts-proto. This lib really is a game changer ❤️
I believe I found a bug in the way ts-proto handles "Value" object in services.
Here is a sample service:
See how
readVariable
returns directly agoogle.protobuf.Value
?When I look at the code generated for the service, I have this:
The
responseSerialize
is typed to "any", butValue.encode
expects the value to be a "Value" object.Same thing,
responseDeserialize
will return a "Value" object, but the end user probably expects a plain object instead.As a result, when reading the result of a call to
readVariable
, the end user needs to manually callValue.unwrap
.The code looks like this:
Same thing server-side where we need to manually call
Value.wrap
.I believe the correct implementation should generate something like:
What do you think?
Also, the same issue happens with streamed return values. For instance:
But, the issue does not happen if the
Value
is part of a message:Bonus: could it be possible have an option to cast protobuf
Value
to Typescriptunknown
(instead ofany
) for type safety?The text was updated successfully, but these errors were encountered: