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> = (
9292export type ValueOf < State > = (
9393 State extends FormState < infer Fields >
9494 ? 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+ )
96104)
97105
98106/** Validate status. */
You can’t perform that action at this time.
0 commit comments