diff --git a/packages/typebox-validator/src/index.ts b/packages/typebox-validator/src/index.ts index aad082be..07ef0eed 100644 --- a/packages/typebox-validator/src/index.ts +++ b/packages/typebox-validator/src/index.ts @@ -2,7 +2,7 @@ import type { TSchema, Static } from '@sinclair/typebox' import { TypeGuard, ValueGuard } from '@sinclair/typebox' import { Value } from '@sinclair/typebox/value' import type { ValueError } from '@sinclair/typebox/value' -import type { Context, Env, MiddlewareHandler, ValidationTargets } from 'hono' +import type { Context, Env, MiddlewareHandler, TypedResponse, ValidationTargets } from 'hono' import { validator } from 'hono/validator' import IsObject = ValueGuard.IsObject import IsArray = ValueGuard.IsArray @@ -57,12 +57,18 @@ export type Hook = ( * ) * ``` */ + +type ExcludeResponseType = T extends Response & TypedResponse ? never : T + export function tbValidator< T extends TSchema, Target extends keyof ValidationTargets, E extends Env, P extends string, - V extends { in: { [K in Target]: Static }; out: { [K in Target]: Static } } + V extends { + in: { [K in Target]: Static } + out: { [K in Target]: ExcludeResponseType> } + } >( target: Target, schema: T,