Fourth oneof option: union-flat? #1077
Replies: 1 comment 1 reply
-
Hello other StephenH! :-) It took me just a few seconds to "get" the approach, but I get the benefits... I think historically I've always considered/assumed the I'm a little cautious about yet-another-approach to oneofs, but I suppose we're already at 3, so what's a fourth... Although, really it seems like maybe your proposal is the same as ts-proto's "default" handling of oneoffs (flat fields, of just a/b/c/d), but just with better typing? Is that right? If so, I'd definitely support, instead of "a new fourth option", just updating our default flat output to have your suggested better typing. ...seems like that would be fine, and I'm sure a breaking change in some way, but it's creating the "same output" in terms of fields/structure, just better types, so I wonder if we could get away with just releasing it as a minor update. If you'd like to try a PR that implements that, that'd be great! |
Beta Was this translation helpful? Give feedback.
-
Hi from one Stephen H to another! I've been using ts-proto extensively for years, so first of all: thanks for the hugely valuable contribution to the community.
Proposal
Add a fourth oneof option, 'unions-flat', which would generate code as follows:
proto:
type:
This appears to combine the advantages of oneof=flat (ease of working with payload, not having to drill down through multiple envelopes, not having to check $case before accessing a key), with the advantages of oneof=unions (constraints preventing multiple exclusive fields being populated, ease of type discrimination). But I've probably missed an issue!
Beta Was this translation helpful? Give feedback.
All reactions