HonoH
Hono14mo ago
this_chord

Zod validator not working

I'm following the tutorial here to set up Hono with Zod validation, but I'm getting the type error seen in the screenshot. Below is my code.

import { type Context, Hono } from "hono";
import { zValidator } from "@hono/zod-validator";
import { z } from "zod";
import { find as findTimezone } from "geo-tz";

const app = new Hono().basePath("/api2");

app.get(
"/timezone",
zValidator(
"query",
z.object({
latitude: z.number().gte(-90).lte(90),
longitude: z.number().gte(-180).lte(180),
}),
),
(c: Context) => {
const { latitude, longitude } = c.req.valid("query");

return c.json({ timeZone: findTimezone(latitude, longitude)[0] });
},
);

Deno.serve({ port: parseInt(Deno.env.get("BACKEND2_PORT") as string) }, app.fetch);
image.png
Web framework built on Web Standards for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
Was this page helpful?