11import { toNestErrors , validateFieldsNatively } from '@hookform/resolvers' ;
2- import { Static , StaticDecode , Type } from '@sinclair/typebox' ;
2+ import { Static , StaticDecode , TObject } from '@sinclair/typebox' ;
33import { TypeCheck } from '@sinclair/typebox/compiler' ;
44import { Value , type ValueError } from '@sinclair/typebox/value' ;
5- import {
6- FieldError ,
7- FieldErrors ,
8- FieldValues ,
9- Resolver ,
10- appendErrors ,
11- } from 'react-hook-form' ;
5+ import { FieldError , Resolver , appendErrors } from 'react-hook-form' ;
126
137function parseErrorSchema (
148 _errors : ValueError [ ] ,
@@ -45,22 +39,6 @@ function parseErrorSchema(
4539 return errors ;
4640}
4741
48- export function typeboxResolver < Input extends FieldValues , Context > (
49- typecheck : TypeCheck < ReturnType < typeof Type . Object < Input > > > ,
50- ) : Resolver <
51- Static < ReturnType < typeof typecheck . Schema > > ,
52- Context ,
53- StaticDecode < ReturnType < typeof typecheck . Schema > >
54- > ;
55-
56- export function typeboxResolver < Input extends FieldValues , Context > (
57- schema : ReturnType < typeof Type . Object < Input > > ,
58- ) : Resolver < Static < typeof schema > , Context , StaticDecode < typeof schema > > ;
59-
60- export function typeboxResolver < Input extends FieldValues , Context , Output > (
61- schema : ReturnType < typeof Type . Object < Input > > ,
62- ) : Resolver < Static < typeof schema > , Context , Output > ;
63-
6442/**
6543 * Creates a resolver for react-hook-form using Typebox schema validation
6644 * @param {Schema | TypeCheck<Schema> } schema - The Typebox schema to validate against
@@ -77,10 +55,10 @@ export function typeboxResolver<Input extends FieldValues, Context, Output>(
7755 * resolver: typeboxResolver(schema)
7856 * });
7957 */
80- export function typeboxResolver < Input extends FieldValues , Context , Output > (
81- schema : ReturnType < typeof Type . Object < Input > > ,
82- ) : Resolver < Static < typeof schema > , Context , Output | Static < typeof schema > > {
83- return async ( values : Static < typeof schema > , _ , options ) => {
58+ export function typeboxResolver < Schema extends TObject , Context > (
59+ schema : Schema | TypeCheck < Schema > ,
60+ ) : Resolver < Static < Schema > , Context , StaticDecode < Schema > > {
61+ return async ( values : Static < Schema > , _ , options ) => {
8462 const errors = Array . from (
8563 schema instanceof TypeCheck
8664 ? schema . Errors ( values )
@@ -91,7 +69,7 @@ export function typeboxResolver<Input extends FieldValues, Context, Output>(
9169
9270 if ( ! errors . length ) {
9371 return {
94- errors : { } as FieldErrors ,
72+ errors : { } ,
9573 values,
9674 } ;
9775 }
0 commit comments