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 {
1010 OptionalizedC ,
1111 OptionalProps ,
1212 RequiredProps ,
13+ Simplify ,
1314} from './utils' ;
1415
1516export const optional = < C extends t . Mixed > ( subCodec : C ) =>
@@ -39,7 +40,10 @@ export const optionalized = <P extends t.Props>(props: P): OptionalizedC<P> => {
3940export const flattened = < Props extends NestedProps > (
4041 name : string ,
4142 props : Props ,
42- ) : t . Type < Flattened < NestedType < Props > > , NestedOutputType < Props > > => {
43+ ) : t . Type <
44+ Simplify < Flattened < NestedType < Props > > > ,
45+ Simplify < NestedOutputType < Props > >
46+ > => {
4347 let flatProps : t . Props = { } ;
4448 for ( const key in props ) {
4549 if ( ! props . hasOwnProperty ( key ) ) {
@@ -69,7 +73,7 @@ export const flattened = <Props extends NestedProps>(
6973 }
7074 flattened = { ...flattened , ...nested [ key ] } ;
7175 }
72- return flattened as Flattened < NestedType < Props > > ;
76+ return flattened as Simplify < Flattened < NestedType < Props > > > ;
7377 } ) ,
7478 ) ,
7579 ( input : any ) => {
@@ -86,7 +90,7 @@ export const flattened = <Props extends NestedProps>(
8690 }
8791 }
8892 }
89- return nested as NestedOutputType < Props > ;
93+ return nested as Simplify < NestedOutputType < Props > > ;
9094 } ,
9195 ) ;
9296} ;
Original file line number Diff line number Diff line change @@ -8,8 +8,9 @@ export type PossiblyUndefinedProps<T extends t.Props> = {
88 [ K in keyof T ] : undefined extends t . TypeOf < T [ K ] > ? K : never ;
99} [ keyof T ] ;
1010
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+ > ;
1314
1415export type OptionalProps < Props extends t . Props > = Pick <
1516 Props ,
@@ -48,3 +49,5 @@ type UnionToIntersection<T> = (T extends any ? (x: T) => any : never) extends (
4849) => any
4950 ? R
5051 : 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