Ask questionsAsynchronous validations

There's support for validating promise types, but I don't see a way to create async validators.

What I'm thinking of is something like this:

const foreignKey = z.string().refine(idExistsAsync, {
  message: "ID not found",

Where idExistsAsync is some function that asynchronously checks some backend to make sure that the value is valid. It returns a promise. Of course this would mean that the entire schema becomes async, so there are some other concerns here when async values are used as fields on objects.


Answer questions chrbala

I agree that the default should be to validate async if that would be okay as a breaking change. It may still make sense to have a synchronous version that requires all parts of the schema to operate synchronously. So maybe parse and parseSync would make sense.


Related questions

No questions were found.
Github User Rank List