From 8a2d4651b0b5570b12e88d081522ae36246f4009 Mon Sep 17 00:00:00 2001 From: Farhad Faraji <68632547+farhadham@users.noreply.github.com> Date: Sun, 5 Jan 2025 12:34:45 +0330 Subject: [PATCH] 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 --- packages/zod-validator/README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/zod-validator/README.md b/packages/zod-validator/README.md index b7a887e5..384b42e7 100644 --- a/packages/zod-validator/README.md +++ b/packages/zod-validator/README.md @@ -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'