1- import { NestedValue , Control } from 'react-hook-form' ;
1+ import {
2+ FieldValues ,
3+ Control ,
4+ Message ,
5+ ValidationRule ,
6+ ValidateResult ,
7+ } from 'react-hook-form' ;
28
39export type ArrayWithLength < N extends number > = { [ K in N ] : any } ;
410
5- export interface DeepPathArray < TValues extends Record < string , any > , TPath >
11+ export interface DeepPathArray < TValues extends FieldValues , TPath >
612 extends ReadonlyArray < string | number > {
713 [ '0' ] : keyof TValues ;
814 [ '1' ] ?: TPath extends {
@@ -73,7 +79,7 @@ export interface DeepPathArray<TValues extends Record<string, any>, TPath>
7379}
7480
7581export type DeepPathArrayValue <
76- TValues extends Record < string , any > ,
82+ TValues extends FieldValues ,
7783 TPath extends DeepPathArray < TValues , TPath >
7884> = TPath extends ArrayWithLength < 0 | 1 | 2 | 3 | 4 | 5 | 6 >
7985 ? any
@@ -91,54 +97,23 @@ export type DeepPathArrayValue<
9197 ? TValues [ TPath [ 0 ] ]
9298 : never ;
9399
94- export type DeepPath < TValues extends Record < string , any > , TPath > =
100+ export type DeepPath < TValues extends FieldValues , TPath > =
95101 | DeepPathArray < TValues , TPath >
96102 | keyof TValues ;
97103
98104export type DeepPathValue <
99- TValues extends Record < string , any > ,
105+ TValues extends FieldValues ,
100106 TPath extends DeepPath < TValues , TPath >
101107> = TPath extends DeepPathArray < TValues , TPath >
102108 ? DeepPathArrayValue < TValues , TPath >
103109 : TPath extends keyof TValues
104110 ? TValues [ TPath ]
105111 : any ;
106112
107- export type NonUndefined < T > = T extends undefined ? never : T ;
108-
109- export type UnpackNestedValue < T > = NonUndefined < T > extends NestedValue < infer U >
110- ? U
111- : NonUndefined < T > extends Date | FileList
112- ? T
113- : NonUndefined < T > extends object
114- ? { [ K in keyof T ] : UnpackNestedValue < T [ K ] > }
115- : T ;
116-
117- export type FieldValuesFromControl <
118- TControl extends Control
119- > = TControl extends Control < infer TFieldValues > ? TFieldValues : never ;
120-
121113export type Options < TControl extends Control > = {
122114 control ?: TControl ;
123115} ;
124116
125- export type Message = string ;
126-
127- export type ValidationValue = boolean | number | string | RegExp ;
128-
129- export type ValidationRule <
130- TValidationValue extends ValidationValue = ValidationValue
131- > = TValidationValue | ValidationValueMessage < TValidationValue > ;
132-
133- export type ValidationValueMessage <
134- TValidationValue extends ValidationValue = ValidationValue
135- > = {
136- value : TValidationValue ;
137- message : Message ;
138- } ;
139-
140- export type ValidateResult = Message | Message [ ] | boolean | undefined ;
141-
142117export type Validate < TFieldValue > = (
143118 data : TFieldValue ,
144119) => ValidateResult | Promise < ValidateResult > ;
@@ -157,7 +132,7 @@ export type Assign<TValues extends object, U extends object> = TValues &
157132 Omit < U , keyof TValues > ;
158133
159134export type ControllerProps <
160- TFieldValues extends Record < string , any > ,
135+ TFieldValues extends FieldValues ,
161136 TFieldName extends DeepPath < TFieldValues , TFieldName > ,
162137 TAs extends 'input' | 'select' | 'textarea'
163138> = Assign <
0 commit comments