diff --git a/package-lock.json b/package-lock.json index 79f26077e..87202da08 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@sinclair/typebox", - "version": "0.32.9", + "version": "0.32.10", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@sinclair/typebox", - "version": "0.32.9", + "version": "0.32.10", "license": "MIT", "devDependencies": { "@arethetypeswrong/cli": "^0.13.2", diff --git a/package.json b/package.json index 6a27860cb..0f1575d2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@sinclair/typebox", - "version": "0.32.9", + "version": "0.32.10", "description": "Json Schema Type Builder with Static Type Resolution for TypeScript", "keywords": [ "typescript", diff --git a/src/type/partial/partial.ts b/src/type/partial/partial.ts index b46ee4af9..961d36f25 100644 --- a/src/type/partial/partial.ts +++ b/src/type/partial/partial.ts @@ -52,7 +52,7 @@ import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type' // prettier-ignore type TFromRest = ( T extends [infer L extends TSchema, ...infer R extends TSchema[]] - ? TFromRest]> + ? TFromRest]> : Acc ) // prettier-ignore @@ -80,27 +80,25 @@ function FromProperties(T: T) { // PartialResolve // ------------------------------------------------------------------ // prettier-ignore -type PartialResolve = ( - T extends TRecursive ? TRecursive> : - T extends TIntersect ? TIntersect> : - T extends TUnion ? TUnion> : - T extends TObject ? TObject> : - TObject<{}> -) -// prettier-ignore -function PartialResolve(T: T): PartialResolve { +function PartialResolve(T: T): TPartial { return ( IsIntersect(T) ? Intersect(FromRest(T.allOf)) : IsUnion(T) ? Union(FromRest(T.anyOf)) : IsObject(T) ? Object(FromProperties(T.properties)) : Object({}) - ) as PartialResolve + ) as TPartial } // ------------------------------------------------------------------ // TPartial // ------------------------------------------------------------------ -export type TPartial = PartialResolve - +// prettier-ignore +export type TPartial = ( + T extends TRecursive ? TRecursive> : + T extends TIntersect ? TIntersect> : + T extends TUnion ? TUnion> : + T extends TObject ? TObject> : + TObject<{}> +) /** `[Json]` Constructs a type where all properties are optional */ export function Partial(T: T, options?: SchemaOptions): TPartialFromMappedResult /** `[Json]` Constructs a type where all properties are optional */ @@ -110,5 +108,5 @@ export function Partial(T: TSchema, options: SchemaOptions = {}): any { if (IsMappedResult(T)) return PartialFromMappedResult(T, options) const D = Discard(T, [TransformKind, '$id', 'required']) as TSchema const R = CloneType(PartialResolve(T), options) - return { ...D, ...R } as any + return { ...D, ...R } as never } diff --git a/src/type/required/required.ts b/src/type/required/required.ts index 1066289b3..56220759b 100644 --- a/src/type/required/required.ts +++ b/src/type/required/required.ts @@ -53,7 +53,7 @@ import { IsMappedResult, IsIntersect, IsUnion, IsObject } from '../guard/type' // prettier-ignore type TFromRest = ( T extends [infer L extends TSchema, ...infer R extends TSchema[]] - ? TFromRest]> + ? TFromRest]> : Acc ) // prettier-ignore @@ -80,28 +80,27 @@ function FromProperties(T: T) { // ------------------------------------------------------------------ // RequiredResolve // ------------------------------------------------------------------ + // prettier-ignore -type TRequiredResolve = ( - T extends TRecursive ? TRecursive> : - T extends TIntersect ? TIntersect> : - T extends TUnion ? TUnion> : - T extends TObject ? TObject> : - TObject<{}> -) -// prettier-ignore -function RequiredResolve(T: T): TRequiredResolve { +function RequiredResolve(T: T): TRequired { return ( IsIntersect(T) ? Intersect(FromRest(T.allOf)) : IsUnion(T) ? Union(FromRest(T.anyOf)) : IsObject(T) ? Object(FromProperties(T.properties)) : Object({}) - ) as TRequiredResolve + ) as TRequired } // ------------------------------------------------------------------ // TRequired // ------------------------------------------------------------------ -export type TRequired = TRequiredResolve - +// prettier-ignore +export type TRequired = ( + T extends TRecursive ? TRecursive> : + T extends TIntersect ? TIntersect> : + T extends TUnion ? TUnion> : + T extends TObject ? TObject> : + TObject<{}> +) /** `[Json]` Constructs a type where all properties are required */ export function Required(T: T, options?: SchemaOptions): TRequiredFromMappedResult /** `[Json]` Constructs a type where all properties are required */