Replies: 2 comments
-
Hi @natebot13 , no we do not have that atm. We could potentially add the lists to the message const, i.e. here: https://github.com/stephenh/ts-proto/blob/main/integration/oneof-unions/oneof.ts#L80 Have something like:
Granted, I'm kind of assuming you'd need more than just the names, like maybe this a map of the We do have a |
Beta Was this translation helpful? Give feedback.
-
Got it, yeah adding the list of oneof types to the message const makes sense. I'm not sure yet about what extra data would be useful to go along with that. type MyProtoType = NonNullable<MyProtoWithOneofs['OptionType']>['$case'];
type ProtoTypeTemplate = { [key of MyProtoType]: boolean }
const ProtoTypeObject: ProtoTypeTemplate {
option1: true,
... // Forced to add all the types here by the compiler
}
const MY_PROTO_TYPES = Object.keys(ProtoTypeObject).map(s => s as MyProtoType) |
Beta Was this translation helpful? Give feedback.
-
I'm able to get a type union of all the oneofs from a proto using something like this:
But it seems that typescript doesn't support the ability to then turn that type union into a list that I can use at runtime. Is there a way to get the list of oneof types as strings? Perhaps ts-proto could generate enums for the oneof types, like other proto compilers?
Beta Was this translation helpful? Give feedback.
All reactions