Automatically applying parse.integer
Let's say I have a type I'm using to validate some API, e.g.
At some point, I also want to use this type to validate form input. As it's formData,the age will be a string not a number.
I know I can do something like this:
However, is there a way to somehow automate the coerce step? I have lots of these types (some of them dynamically created) and I'd rather avoid having to manually create an extra type to pick out the numeric fields and parse.integer them.
Maybe there's some way I can automatically pick out the number properties from a type and automatically build the coerce step so that parse.integer is only applied to any properties that are numeric in the final schema?
I'm fairly new to this, so it could just be my lack of Typescript skill. Any pointers would be much appreciated.
At some point, I also want to use this type to validate form input. As it's formData,the age will be a string not a number.
I know I can do something like this:
However, is there a way to somehow automate the coerce step? I have lots of these types (some of them dynamically created) and I'd rather avoid having to manually create an extra type to pick out the numeric fields and parse.integer them.
Maybe there's some way I can automatically pick out the number properties from a type and automatically build the coerce step so that parse.integer is only applied to any properties that are numeric in the final schema?
I'm fairly new to this, so it could just be my lack of Typescript skill. Any pointers would be much appreciated.
