@@ -18,6 +18,16 @@ export declare type Decoded<Model, AltErr = never> = Model extends Decoder<infer
18
18
export declare type DecoderObject < Val , AltErr extends any > = {
19
19
[ Key in keyof Val ] : ComposedDecoder < Val [ Key ] , AltErr > ;
20
20
} ;
21
+ /**
22
+ * Treats nullable fields as optional
23
+ * https://github.com/Microsoft/TypeScript/issues/12400#issuecomment-758523767
24
+ */
25
+ export declare type OptionalNullable < T > = Optional < T > & Required < T > ;
26
+ declare type Optional < T > = Partial < Pick < T , KeysOfType < T , null | undefined > > > ;
27
+ declare type Required < T > = Omit < T , KeysOfType < T , null | undefined > > ;
28
+ declare type KeysOfType < T , SelectedType > = {
29
+ [ key in keyof T ] : SelectedType extends T [ key ] ? key : never ;
30
+ } [ keyof T ] ;
21
31
declare type PathElement = TypedObject | Index | ObjectKey | Array < any > ;
22
32
export declare class Index {
23
33
index : number ;
@@ -87,7 +97,7 @@ export declare function oneOf<Val, AltErr = never>(decoders: ReadonlyArray<Compo
87
97
* });
88
98
* ```
89
99
*/
90
- export declare function object < Val , AltErr > ( name : string , decoders : DecoderObject < Val , AltErr > ) : Decoder < Val , AltErr > ;
100
+ export declare function object < Val , AltErr > ( name : string , decoders : DecoderObject < Val , AltErr > ) : Decoder < OptionalNullable < Val > , AltErr > ;
91
101
/**
92
102
* Creates an intersection between two decoders. Equivalent to TypeScript's `&` operator.
93
103
*
0 commit comments