diff --git a/package.json b/package.json index 776f37f..7ff6b59 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "schemawax", - "version": "1.0.2", + "version": "1.0.3", "description": "Tiny typed data decoder", "homepage": "https://github.com/michaljanocko/schemawax", "repository": "git@github.com:michaljanocko/schemawax.git", diff --git a/src/index.ts b/src/index.ts index 04a8174..a6c1ec7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -192,7 +192,7 @@ export const keyValuePairs = (decoder: Decoder): Decoder> -type WithoutPartialUnknown = T extends infer U & Partial ? U : never +type OmitEmptyPartial = T extends infer U & Partial<{ [x: string]: any }> ? U : never type ObjectType = D extends { [K in keyof infer U]: Decoder<(infer U)[K]> } ? U : never const required = ( @@ -235,17 +235,17 @@ export const object = ( required?: D optional?: E } -): Decoder & Partial>>> => createDecoder({ +): Decoder & Partial>>> => createDecoder({ forceDecode: (data) => { checkDefined(data) - const result: Partial & Partial>>> = {} + const result: Partial & Partial>>> = {} if (struct.required !== undefined) { Object.assign(result, required(struct.required).forceDecode(data)) } if (struct.optional !== undefined) { Object.assign(result, partial(struct.optional).forceDecode(data)) } - return result as WithoutPartialUnknown & Partial>> + return result as OmitEmptyPartial & Partial>> } })