H
Hono6mo ago
Earnstein

How to Resolve "Argument of type MiddlewareHandler Error"

The lines of code where I used zValidator throws the error "Argument of type MiddlewareHandler Error". Here is the code snippet of how I am using the validator. jobRouter .route("/") .post( zValidator("json", JobSchema, (result, c) => { if (!result.success) { return c.json({ error: result.error.issues }, StatusCodes.BAD_REQUEST); } }), httpCreateJob ) Here is the Jobschema definition export const JobSchema = z.object({ position: z.string().min(1, {message: "Position is required"}).max(50), company: z.string().min(1, {message:"Company is required"}).max(50), jobStatus: z.enum([jobStatus.interview, jobStatus.declined, jobStatus.pending]).optional(), jobType: z.enum([jobType.fullTime, jobType.internship, jobType.partTime, jobType.remote]).optional(), jobLocation: z.string().min(1, "Job location is required").optional(), }) While this is not breaking my code, I don't like the red lines on my screen and would appreciate any help to resolve this.
4 Replies
Nico
Nico6mo ago
Where are you getting the issue which part of the code Nevermind I see you mentioned that above. Is there any other information about the issue?
Earnstein
EarnsteinOP6mo ago
There's really no other information, perhaps I should send the entire error message. My hint is that it's probably because I'm not following hono's best practices as I've defined my controllers in a separate file.
Nico
Nico6mo ago
Yes splitting your route and controller into different files will cause ts issues
Nico
Nico6mo ago
Best Practices - Hono
Ultrafast web framework for Cloudflare Workers, Fastly Compute, Deno, Bun, Vercel, Node.js, and others. Fast, but not only fast.
Want results from more Discord servers?
Add your server