Build a parser that validates input against a Zod schema and returns a Result. Throws a wrapped Error (with the original as cause) if the schema uses async refinements or transforms — use fromZodAsync for those.
input
Error
cause
const User = z.object({ id: z.string(), age: z.number() }) const parseUser = fromZod(User) const r = parseUser(JSON.parse(body)) if (r.ok) save(r.value) else console.error(r.error.issues) Copy
const User = z.object({ id: z.string(), age: z.number() }) const parseUser = fromZod(User) const r = parseUser(JSON.parse(body)) if (r.ok) save(r.value) else console.error(r.error.issues)
Build a parser that validates
inputagainst a Zod schema and returns a Result. Throws a wrappedError(with the original ascause) if the schema uses async refinements or transforms — use fromZodAsync for those.