Skip to content

Commit

Permalink
feat: pass narrower type to zod validation hook
Browse files Browse the repository at this point in the history
  • Loading branch information
bartekbp committed Sep 24, 2024
1 parent 37321e6 commit 7fc598c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/zod-validator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { Context, MiddlewareHandler, Env, ValidationTargets, TypedResponse,
import { validator } from 'hono/validator'
import type { z, ZodSchema, ZodError } from 'zod'

export type Hook<T, E extends Env, P extends string, O = {}> = (
result: ({ success: true; data: T} | { success: false; error: ZodError; data: T }) & {target: keyof ValidationTargets },
export type Hook<T, E extends Env, P extends string, Target extends keyof ValidationTargets = keyof ValidationTargets, O = {}> = (
result: ({ success: true; data: T} | { success: false; error: ZodError; data: T }) & {target: Target },
c: Context<E, P>,
) => Response | void | TypedResponse<O> | Promise<Response | void | TypedResponse<O>>

Expand Down Expand Up @@ -38,7 +38,7 @@ export const zValidator = <
>(
target: Target,
schema: T,
hook?: Hook<z.infer<T>, E, P>
hook?: Hook<z.infer<T>, E, P, Target>
): MiddlewareHandler<E, P, V> =>
// @ts-expect-error not typed well
validator(target, async (value, c) => {
Expand Down

0 comments on commit 7fc598c

Please sign in to comment.