Comments (5)
neater alternative
const schema = z.object({
limit: z.string().pipe(z.coerce.number().min(1).max(20)).optional(),
});
from middleware.
Hi @ryoppippi,
Does the error disappear if you change the line to the following?
const schema = z.object({ userID: z.number().int() })
to
const schema = z.object({ userID: z.string() })
from middleware.
me too!
import { Hono } from "hono/mod.ts";
import { z } from "zod/mod.ts";
// import { validator } from "hono/validator/index.ts";
import { zValidator } from "npm:@hono/zod-validator";
const router = new Hono();
const schema = z.object({
name: z.string(),
age: z.number(),
});
router.post(
"/register",
zValidator("form", schema),
async (c) => {
const data = await c.req.parseBody()
return c.json({ hello: "world", data });
}
);
export const registerRouter = (app: Hono) => app.route("/", router);
ts error:
No overload matches this call.
The last overload gave the following error.
Argument of type 'MiddlewareHandler<Env, string, any>' is not assignable to parameter of type 'H<Env, "/register", {}, {}>'.
Type 'MiddlewareHandler<Env, string, any>' is not assignable to type 'Handler<Env, "/register", {}, {}>'.
Types of parameters 'c' and 'c' are incompatible.
Type 'Context<Env, "/register", {}>' is not assignable to type 'Context<Env, string, any>'.
Types have separate declarations of a private property '_req'.
from middleware.
Fix like the following:
const schema = z.object({
name: z.string(),
age: z.number(),
});
// To
const schema = z.object({
name: z.string(),
age: z.string(),
});
Because the "form" values should not be number
.
from middleware.
hi @yusukebe !!
Thanks!
I changed like below and it works fine!!! :
const schema = z.object({
name: z.string(),
age: z.string().transform(v=>parseInt(v)).refine(v=>!isNaN(v), {message: 'not a number'})
});
from middleware.
Related Issues (20)
- @hono/zod-validator doesn't support nullable values HOT 2
- Type Error when trying to validate 'params' with zValidator - Types of parameters 'c' and 'c' are incompatible HOT 6
- Example with Supabase AUTH HOT 1
- zod-openapi /doc endpoint returns 500 if param name is wrong HOT 2
- Cannot give nullish schema to zValidator HOT 3
- Cannot use preprocess and coerce in zValidator. HOT 8
- Authorization Header Not Working with Swagger in Hono/Zod-OpenAPI HOT 4
- [zod-openapi] Problem with strict type checking of return values HOT 5
- [zod-validator] zValidator type error with param HOT 6
- How to Insert Custom Middleware Using @hono/zod-openapi ? HOT 2
- basicAuth for serveStatic HOT 1
- Issues with peer dependencies found, using @hono/oauth-providers HOT 1
- how to access env outside fetch, when working with oauth-handlers HOT 1
- Possible enhancement for @hono/typebox-validator ?
- [zod-openapi] hono client type inference does not work with a chained route and middleware HOT 2
- @hono/qwik-city on Cloudflare Pages? HOT 3
- zod-validator type error HOT 4
- Auth.js middleware error HOT 1
- `@hono/zod-openapi` is not compatible with HonoX HOT 3
- [zod-openapi][feature request] set route specific middleware from zod-openapi createRoute
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from middleware.