Skip to content

Is there an equivalent of Zod's inferFlattenedErrors for with-zod? #76

Answered by airjp73
zayenz asked this question in Q&A
Discussion options

You must be logged in to vote

We don't currently have a way to infer the type of the error result -- the best we have is ValidationErrorResponseData which uses Record<string, string> for the field errors. I'm also not totally sure if we can provide this inference. z.inferFlattenedErrors doesn't produce an accurate type for our uses so we'd potentially have to find some way to implement this type from scratch for both zod and yup.

Example of why z.inferFlattenedErrors isn't accurate. If you have this schema

const s = z.object({
  names: z.array(z.string())
});

Then you get this type using z.inferFlattenedErrors

type ErrorType = z.inferFlattenedErrors<typeof s>['fieldErrors'];
// { names?: string[] | undefined }

But the…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@zayenz
Comment options

@airjp73
Comment options

@zayenz
Comment options

Answer selected by zayenz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants