File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff line change
1
+ import { Validatable , ValueOf } from './types'
2
+
3
+ // https://stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript/68963796#68963796
4
+ export type Equal < X , Y > = (
5
+ ( < T > ( ) => T extends X ? 1 : 2 ) extends
6
+ ( < T > ( ) => T extends Y ? 1 : 2 )
7
+ ? true
8
+ : false
9
+ )
10
+
11
+ function assertEqual < T , S > ( ..._args : Equal < T , S > extends true ? [ ] : [ never ] ) { }
12
+
13
+ describe ( 'ValueOf' , ( ) => {
14
+ it ( 'should work well with Validatable' , ( ) => {
15
+ const a = { } as Validatable < string >
16
+ assertEqual < ValueOf < typeof a > , string > ( )
17
+ } )
18
+ } )
Original file line number Diff line number Diff line change @@ -92,7 +92,15 @@ export type ValueOfFields<Fields> = (
92
92
export type ValueOf < State > = (
93
93
State extends FormState < infer Fields >
94
94
? ValueOfFields < Fields >
95
- : ValueOfFieldState < State >
95
+ : (
96
+ State extends FieldState < infer V >
97
+ ? V
98
+ : (
99
+ State extends Validatable < unknown , infer V >
100
+ ? V
101
+ : never
102
+ )
103
+ )
96
104
)
97
105
98
106
/** Validate status. */
You can’t perform that action at this time.
0 commit comments