plainfp - v0.1.0
    Preparing search index...

    Function fromZod

    • 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.

      Type Parameters

      • S extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

      Parameters

      • schema: S

      Returns (input: unknown) => ResultType<output<S>, ZodError<unknown>>

      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)