improbable-eng / ts-protoc-gen

Protocol Buffers Compiler (protoc) plugin for TypeScript and gRPC-Web.
Apache License 2.0
1.37k stars 172 forks source link

Could we support friendlier object-literal syntax for service methods? #288

Open githorse opened 3 years ago

githorse commented 3 years ago

In grpc-js, at least according to the GRPC.io docs, I can do things like this:

client.sayGoodNight({name: 'Gracie'}, ... );

But with the Typescript version that doesn't seem to be possible; instead, I need to create a HelloRequest object explicitly and set the name:

const request = new GoodNightRequest()
request.setName('Gracie')
client.sayGoodNight(request, ... )

Personally I'm irked by both the mutable state and the boilerplate of the setter syntax and strongly prefer the object-literal {name: 'Gracie'} version. (For me that's most of the fun of writing Javascript!) Does, or could, this library support that streamlined syntax? I see that GoodNightRequest.AsObject in good_night_pb.d.ts actually does define the necessary interface, but it doesn't look like sayGoodNight will accept anything but an instance of the GoodNightRequest class.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.