Skip to content

Commit

Permalink
docs(zod-validator) - Update README.md to include an example with a c…
Browse files Browse the repository at this point in the history
…ustom validator wrapper for improved type inference (#922)

* docs: add custom validator example for improved type inference

* Update README.md - removed default value of target
  • Loading branch information
farhadham authored Jan 5, 2025
1 parent 88135cb commit 8a2d465
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/zod-validator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,18 @@ import { ZodSchema } from "zod";
import type { ValidationTargets } from "hono";
import { zValidator as zv } from "@hono/zod-validator";

export const zValidator = (target: keyof ValidationTargets, schema: ZodSchema) =>
zv(target, schema, (result, c) => {
if (!result.success) {
throw new HTTPException(400, { cause: result.error });
}
})
export const zValidator = <
T extends ZodSchema,
Target extends keyof ValidationTargets
>(
target: Target,
schema: T
) =>
zv(target, schema, (result, c) => {
if (!result.success) {
throw new HTTPException(400, { cause: result.error });
}
});

// usage
import { zValidator } from './validator-wrapper'
Expand Down

0 comments on commit 8a2d465

Please sign in to comment.