diff --git a/packages/io-ts-http/src/combinators.ts b/packages/io-ts-http/src/combinators.ts index fd85a04c..a54654d2 100644 --- a/packages/io-ts-http/src/combinators.ts +++ b/packages/io-ts-http/src/combinators.ts @@ -10,6 +10,7 @@ import { OptionalizedC, OptionalProps, RequiredProps, + Simplify, } from './utils'; export const optional = (subCodec: C) => @@ -39,7 +40,10 @@ export const optionalized =

(props: P): OptionalizedC

=> { export const flattened = ( name: string, props: Props, -): t.Type>, NestedOutputType> => { +): t.Type< + Simplify>>, + Simplify> +> => { let flatProps: t.Props = {}; for (const key in props) { if (!props.hasOwnProperty(key)) { @@ -69,7 +73,7 @@ export const flattened = ( } flattened = { ...flattened, ...nested[key] }; } - return flattened as Flattened>; + return flattened as Simplify>>; }), ), (input: any) => { @@ -86,7 +90,7 @@ export const flattened = ( } } } - return nested as NestedOutputType; + return nested as Simplify>; }, ); }; diff --git a/packages/io-ts-http/src/utils.ts b/packages/io-ts-http/src/utils.ts index 49aa061f..a071ee57 100644 --- a/packages/io-ts-http/src/utils.ts +++ b/packages/io-ts-http/src/utils.ts @@ -8,8 +8,9 @@ export type PossiblyUndefinedProps = { [K in keyof T]: undefined extends t.TypeOf ? K : never; }[keyof T]; -type Optionalized = Omit> & - Partial>>; +type Optionalized = Simplify< + Omit> & Partial>> +>; export type OptionalProps = Pick< Props, @@ -48,3 +49,5 @@ type UnionToIntersection = (T extends any ? (x: T) => any : never) extends ( ) => any ? R : never; + +export type Simplify = T extends unknown ? { [K in keyof T]: T[K] } : never;