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

The proper user code #310

Open OnkelTem opened 2 years ago

OnkelTem commented 2 years ago

Hi everybody.

It seems like I'm missing the proper way to write an app for the code, generated by this plugin.

Imagine a message with like 30 fields. So it's gonna be a class with 60 methods now, and it doesn't look like there are some shortcuts. I only found the <MessageType>.AsObject type and toObject() utility which come in handy when you work with results.

However, to create a message, I write a code like:

const req = new Message1();
if (field1 != null) {
  req.setField1(field1);
}
if (field2 != null) {
  req.setField2(field2);
}
// ...
if (fieldN != null) {
  req.setFieldN(fieldN);
}

`- i.e. self-repeating, not nice, hard to maintain etc. For example, with OpenAPI I wouldn't need just any of that. I would gladly write a few wrappers, but it doesn't seem to be possible as well, because there are no prop lists to iterate over.

So how do you folks do it? Or are you really typing all this?