File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ import {
10
10
OptionalizedC ,
11
11
OptionalProps ,
12
12
RequiredProps ,
13
+ Simplify ,
13
14
} from './utils' ;
14
15
15
16
export const optional = < C extends t . Mixed > ( subCodec : C ) =>
@@ -39,7 +40,10 @@ export const optionalized = <P extends t.Props>(props: P): OptionalizedC<P> => {
39
40
export const flattened = < Props extends NestedProps > (
40
41
name : string ,
41
42
props : Props ,
42
- ) : t . Type < Flattened < NestedType < Props > > , NestedOutputType < Props > > => {
43
+ ) : t . Type <
44
+ Simplify < Flattened < NestedType < Props > > > ,
45
+ Simplify < NestedOutputType < Props > >
46
+ > => {
43
47
let flatProps : t . Props = { } ;
44
48
for ( const key in props ) {
45
49
if ( ! props . hasOwnProperty ( key ) ) {
@@ -69,7 +73,7 @@ export const flattened = <Props extends NestedProps>(
69
73
}
70
74
flattened = { ...flattened , ...nested [ key ] } ;
71
75
}
72
- return flattened as Flattened < NestedType < Props > > ;
76
+ return flattened as Simplify < Flattened < NestedType < Props > > > ;
73
77
} ) ,
74
78
) ,
75
79
( input : any ) => {
@@ -86,7 +90,7 @@ export const flattened = <Props extends NestedProps>(
86
90
}
87
91
}
88
92
}
89
- return nested as NestedOutputType < Props > ;
93
+ return nested as Simplify < NestedOutputType < Props > > ;
90
94
} ,
91
95
) ;
92
96
} ;
Original file line number Diff line number Diff line change @@ -8,8 +8,9 @@ export type PossiblyUndefinedProps<T extends t.Props> = {
8
8
[ K in keyof T ] : undefined extends t . TypeOf < T [ K ] > ? K : never ;
9
9
} [ keyof T ] ;
10
10
11
- type Optionalized < T > = Omit < T , PossiblyUndefinedKeys < T > > &
12
- Partial < Pick < T , PossiblyUndefinedKeys < T > > > ;
11
+ type Optionalized < T > = Simplify <
12
+ Omit < T , PossiblyUndefinedKeys < T > > & Partial < Pick < T , PossiblyUndefinedKeys < T > > >
13
+ > ;
13
14
14
15
export type OptionalProps < Props extends t . Props > = Pick <
15
16
Props ,
@@ -48,3 +49,5 @@ type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (
48
49
) => any
49
50
? R
50
51
: never ;
52
+
53
+ export type Simplify < T > = T extends unknown ? { [ K in keyof T ] : T [ K ] } : never ;
You can’t perform that action at this time.
0 commit comments