Aidan647 - how can I validate other1 and other2...
how can I validate
other1
and other2
? (function validation is optional)
9 Replies
Something like that?
I've never used Zod to parse a function like that though, so I'd be a little wary of doing that.
otherwise, I guess you can pass it like:
"message": "Expected object, received function"
tried z.function and z.object
and z.object and z.function
Yeah, I think you'll have to separate the function and object parsing.
I don't need to parse function
just object part in function
Cool, then yeah, something like my other solution where you build an object out of the properties of the function should work.
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
you gave me an idea and it works
so basically I validate
other1
and other2
separately
Yeah, basically. But, note:
parse
does not narrow the type of the input data, it produces a value of the output type, if that makes sense. So you'll want to capture the result of parsing and use that rather than using the original func.other1
unless you trust that it exists anyway.I have it in pretty odd place where I don't save the result of
parse
, I just need it to crash if it does not have them