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 targetpull/925/head
parent
88135cbee5
commit
8a2d4651b0
|
@ -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) =>
|
||||
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'
|
||||
|
|
Loading…
Reference in New Issue