ts-proto icon indicating copy to clipboard operation
ts-proto copied to clipboard

Address optional fields issue with Exact

Open paralin opened this issue 3 years ago • 3 comments

The README says that the default is not to use optional fields, and the main reason is to avoid accidentally setting the wrong field name, because we don't have Exact<T> to control ensuring that unknown fields don't exist.

However, it seems that these days Exact is defined by ts-proto, so, could it be used to ensure that the objects passed to encode() don't have any unknown fields?

paralin avatar Jun 18 '22 20:06 paralin

Ah yeah, good question...

Technically the readme mentions three reasons (typo prevention, more consistent API for readers, and ensuring proper message initialization), and you're right ts-proto Exact tries to/should prevent the first one, but there are still the other two rationales.

Dunno, I don't feel as strongly about this optional/required issue as I did when first writing ts-proto, but I'm tempted to leave things as-is.

We could flip the default I guess, to useOptionals=all, but I don't have any analytics/data points on how many ts-protos users are using/overriding the default.

stephenh avatar Jun 28 '22 19:06 stephenh

FWIW, in my opinion changing default behaviour is a breaking change (for build pipeles), and warrants a major release, so I would advocate against it. We are explicitly setting useOptionals=all, so it wouldn't affect us though.

In any case it sounds like the documentation should probably be rephrased a bit?

oyvindwe avatar Jun 28 '22 20:06 oyvindwe

@oyvindwe yeah, agreed; fwiw I think ts-proto is due to have a major / 2.0 version release that upgrades some of the defaults / renames of the flags / etc. Maybe if protobuf.js every ships long-js 5.0.0 support (which is ESM). :-)

Also fwiw I'm unlikely personally to drive that next around of 2.0/etc. release/clean up, just b/c personally I'm at a company now that uses GraphQL, so I'm not hands-on-keyboard using protobuf anymore.

I'm still happy to steward ts-proto along, but also am really open to a core group of contributors self-organizing and pushing the project to its next stage, if that's something anyone is interested in.

stephenh avatar Jun 29 '22 03:06 stephenh