-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protovalidate
-aware type generation
#966
Comments
Thanks for opening the issue, Andrew! I'm not sure that the generated types should be modified by protovalidate rules. There's no guarantee that a given message has been validated before serialization, so you could easily get a runtime error when parsing a message that isn't valid. But I've been thinking that |
Nice, that sounds good to me! |
+1 for this! |
It would be really cool if the generated TypeScript types were aware of
protovalidate
rules.For example
?
optional qualifier for message fields withrequired
undefined
case for oneofs withrequired
Extract<>
types andOmit<>
types for fields within
/not_in
There are probably other rules that can be translated into type constraints (e.g.
const
), but those are the ones that we're making use of.It makes the resulting code a lot easier to work with if you have strict TypeScript config because you'll get compile errors rather than runtime errors if you fail to set a required field on a message, and you don't have to deal with impossible situations like something potentially being
undefined
that you know can never beundefined
because of the validation rules.We're currently achieving this by doing some nasty regex-based post-processing of the generated code but I would love to stop doing that 🙈
The text was updated successfully, but these errors were encountered: