refactor(typebox-validator): fix the type error (#1079)

pull/1081/head
Yusuke Wada 2025-03-29 09:02:20 +09:00 committed by GitHub
parent 88d3b5c637
commit 37dbba2b8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 2 deletions

View File

@ -2,7 +2,7 @@ import type { TSchema, Static } from '@sinclair/typebox'
import { TypeGuard, ValueGuard } from '@sinclair/typebox' import { TypeGuard, ValueGuard } from '@sinclair/typebox'
import { Value } from '@sinclair/typebox/value' import { Value } from '@sinclair/typebox/value'
import type { ValueError } 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 { validator } from 'hono/validator'
import IsObject = ValueGuard.IsObject import IsObject = ValueGuard.IsObject
import IsArray = ValueGuard.IsArray import IsArray = ValueGuard.IsArray
@ -57,12 +57,18 @@ export type Hook<T, E extends Env, P extends string> = (
* ) * )
* ``` * ```
*/ */
type ExcludeResponseType<T> = T extends Response & TypedResponse<any> ? never : T
export function tbValidator< export function tbValidator<
T extends TSchema, T extends TSchema,
Target extends keyof ValidationTargets, Target extends keyof ValidationTargets,
E extends Env, E extends Env,
P extends string, P extends string,
V extends { in: { [K in Target]: Static<T> }; out: { [K in Target]: Static<T> } } V extends {
in: { [K in Target]: Static<T> }
out: { [K in Target]: ExcludeResponseType<Static<T>> }
}
>( >(
target: Target, target: Target,
schema: T, schema: T,