@@ -11,6 +11,7 @@ import type {
11
11
import { useState , useContext , useEffect , useRef , useMemo } from 'react' ;
12
12
import { getNamePath , getValue } from './utils/valueUtil' ;
13
13
import { isFormInstance } from './utils/typeUtil' ;
14
+ import type { DeepNamePath , GetNameType } from './namePathType' ;
14
15
15
16
type ReturnPromise < T > = T extends Promise < infer ValueType > ? ValueType : never ;
16
17
type GetGeneric < TForm extends FormInstance > = ReturnPromise < ReturnType < TForm [ 'validateFields' ] > > ;
@@ -37,39 +38,15 @@ const useWatchWarning =
37
38
: ( ) => { } ;
38
39
39
40
function useWatch <
40
- TDependencies1 extends keyof GetGeneric < TForm > ,
41
- TForm extends FormInstance ,
42
- TDependencies2 extends keyof GetGeneric < TForm > [ TDependencies1 ] ,
43
- TDependencies3 extends keyof GetGeneric < TForm > [ TDependencies1 ] [ TDependencies2 ] ,
44
- TDependencies4 extends keyof GetGeneric < TForm > [ TDependencies1 ] [ TDependencies2 ] [ TDependencies3 ] ,
41
+ TForm extends FormInstance = FormInstance ,
42
+ const TDependencies extends DeepNamePath < GetGeneric < TForm > > = any ,
45
43
> (
46
- dependencies : [ TDependencies1 , TDependencies2 , TDependencies3 , TDependencies4 ] ,
44
+ dependencies : TDependencies ,
47
45
form ?: TForm | WatchOptions < TForm > ,
48
- ) : GetGeneric < TForm > [ TDependencies1 ] [ TDependencies2 ] [ TDependencies3 ] [ TDependencies4 ] ;
49
-
50
- function useWatch <
51
- TDependencies1 extends keyof GetGeneric < TForm > ,
52
- TForm extends FormInstance ,
53
- TDependencies2 extends keyof GetGeneric < TForm > [ TDependencies1 ] ,
54
- TDependencies3 extends keyof GetGeneric < TForm > [ TDependencies1 ] [ TDependencies2 ] ,
55
- > (
56
- dependencies : [ TDependencies1 , TDependencies2 , TDependencies3 ] ,
57
- form ?: TForm | WatchOptions < TForm > ,
58
- ) : GetGeneric < TForm > [ TDependencies1 ] [ TDependencies2 ] [ TDependencies3 ] ;
59
-
60
- function useWatch <
61
- TDependencies1 extends keyof GetGeneric < TForm > ,
62
- TForm extends FormInstance ,
63
- TDependencies2 extends keyof GetGeneric < TForm > [ TDependencies1 ] ,
64
- > (
65
- dependencies : [ TDependencies1 , TDependencies2 ] ,
66
- form ?: TForm | WatchOptions < TForm > ,
67
- ) : GetGeneric < TForm > [ TDependencies1 ] [ TDependencies2 ] ;
68
-
69
- function useWatch < TDependencies extends keyof GetGeneric < TForm > , TForm extends FormInstance > (
70
- dependencies : TDependencies | [ TDependencies ] ,
71
- form ?: TForm | WatchOptions < TForm > ,
72
- ) : GetGeneric < TForm > [ TDependencies ] ;
46
+ ) : GetNameType <
47
+ GetGeneric < TForm > ,
48
+ TDependencies extends readonly any [ ] ? TDependencies : [ TDependencies ]
49
+ > ;
73
50
74
51
function useWatch < TForm extends FormInstance > (
75
52
dependencies : [ ] ,
0 commit comments