Skip to content

Commit 8a2d465

Browse files
authored
docs(zod-validator) - Update README.md to include an example with a custom validator wrapper for improved type inference (#922)
* docs: add custom validator example for improved type inference * Update README.md - removed default value of target
1 parent 88135cb commit 8a2d465

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

packages/zod-validator/README.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,18 @@ import { ZodSchema } from "zod";
4747
import type { ValidationTargets } from "hono";
4848
import { zValidator as zv } from "@hono/zod-validator";
4949

50-
export const zValidator = (target: keyof ValidationTargets, schema: ZodSchema) =>
51-
zv(target, schema, (result, c) => {
52-
if (!result.success) {
53-
throw new HTTPException(400, { cause: result.error });
54-
}
55-
})
50+
export const zValidator = <
51+
T extends ZodSchema,
52+
Target extends keyof ValidationTargets
53+
>(
54+
target: Target,
55+
schema: T
56+
) =>
57+
zv(target, schema, (result, c) => {
58+
if (!result.success) {
59+
throw new HTTPException(400, { cause: result.error });
60+
}
61+
});
5662

5763
// usage
5864
import { zValidator } from './validator-wrapper'

0 commit comments

Comments
 (0)