jointz icon indicating copy to clipboard operation
jointz copied to clipboard

combine two object validators

Open prbxr opened this issue 3 years ago • 2 comments

Hi

How do I join to validators?

const a = jointz.object({ c: jointz.string() });
const b = jointz.object({ d: jointz.string() });

How to do a validator with type
type ab = { c: string; d: string; }

and operator needed

As when we do it typescript type TAB = A & B

prbxr avatar Jun 24 '21 10:06 prbxr

There is no method to combine two object validators. You can do something like this though

const aFields = { c: jointz.string() };
const bFields = { d: jointz.string() };

const ab = jointz.object({...aFields, ...bFields})

moodysalem avatar Jun 24 '21 14:06 moodysalem

I added #extend, #pick, #omit, which helps, but not exactly combine like you asked 😅

moodysalem avatar Sep 02 '22 14:09 moodysalem