New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[zod-validator] c.req.valid("json")
returning never
#77
Comments
I can fix it temporarily by changing line 13 to: const data: z.infer<typeof schema> = c.req.valid("json"); But I'm curious why the inference isn't working correctly. Any ideas? |
Hi @geelen ! Try the following two:
|
Wow, |
Hey @yusukebe, I've got a similar problem to this but I've already got Here's what I'm working with.
|
The problem is that the handler is created separately from the application. https://hono.dev/guides/best-practices#factory-createhandlers-in-hono-factory You can use the factory method: import { zValidator } from '@hono/zod-validator'
import { Factory } from 'hono/factory'
import { z } from 'zod'
export const loginSchema = z.object({
email: z.string().email(),
})
const factory = new Factory()
export const login = factory.createHandlers(zValidator('json', loginSchema), (c) => {
const data = c.req.valid('json')
// ...
return c.json(undefined, 202)
}) |
Taking the example from the README:
Gives me this error:
Not sure what I'm doing wrong, my tsconfig is pretty minimal:
The text was updated successfully, but these errors were encountered: