arktypea
arktype9mo ago
Valency

zod .refine() equivalent? min/max validation

Hello!

I'm currently exploring arktype to replace zod and was wondering if it was possible to replicate the functionality that zod provides via .refine() in arktype.

eg, performing a validation using multiple fields that relate to one another in an object. in this case, letting a user set a custom min/max range in two different inputs:

const minMaxAmount = z
    .object({
      min: z.number(),
      max: z.number(),
    })
    .refine(({ min, max }) => min < max, {
      message: 'Range minimum must be less than range maximum',
      path: ['min'],
    }),


Thanks for the cool library!
Was this page helpful?