From 76f00959c6169e186330ebdc30eee6a4a4fad4c6 Mon Sep 17 00:00:00 2001 From: Yusuke Wada Date: Sat, 29 Mar 2025 09:02:20 +0900 Subject: [PATCH] refactor(typebox-validator): fix the type error (#1079) --- packages/typebox-validator/src/index.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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,