You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Suppose I have a type with a bunch of constraints on it backing a form validator. I want to evaluate is "mostly correct" rapidly by verifying everything that is not an async check and then decide how to handle the async updates.
constDog=z.object({name: z.string(),age: z.number(),breed: z.string().refine(async(breed)=>{// validate breed is recognizedreturntrue;}),});
I want something like:
constmyPet=Dog.parse({ ... },{skipAsync: true});// myPet is not yet a Dog// can do something hereconstfinishedPet=awaitDog.parseAsync(myPet);// finishedPet is Dog
Is there a better way to do this besides extracting the async refinements from the original object:
constMaybeDog=z.object({name: z.string(),age: z.number(),breed: z.string(),});constDog=MaybeDog.extend({breed: Dog.shape.breed.refine(async(breed)=>{// validate breed is recognizedreturntrue;}),});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Suppose I have a type with a bunch of constraints on it backing a form validator. I want to evaluate is "mostly correct" rapidly by verifying everything that is not an async check and then decide how to handle the async updates.
I want something like:
Is there a better way to do this besides extracting the async refinements from the original object:
Beta Was this translation helpful? Give feedback.
All reactions