diff --git a/src/type/builder/index.ts b/src/type/builder/index.ts index bc2874399..60f49c2ab 100644 --- a/src/type/builder/index.ts +++ b/src/type/builder/index.ts @@ -38,6 +38,6 @@ import * as TypeBuilder from './type' import { JavaScriptTypeBuilder } from './javascript' /** JavaScript Type Builder with Static Resolution for TypeScript */ -const Type: InstanceType = TypeBuilder +const Type = TypeBuilder as InstanceType export { JavaScriptTypeBuilder } export { Type } diff --git a/src/type/builder/json.ts b/src/type/builder/json.ts index a277648bd..db7c31298 100644 --- a/src/type/builder/json.ts +++ b/src/type/builder/json.ts @@ -112,7 +112,7 @@ export class JsonTypeBuilder { } /** `[Json]` Creates a Composite object type */ public Composite(objects: [...T], options?: ObjectOptions): TComposite { - return Composite(objects, options) + return Composite(objects, options) as any // (error) TS 5.4.0-dev - review TComposite implementation } /** `[Json]` Creates a dereferenced type */ public Deref(schema: T, references: TSchema[]): TDeref { diff --git a/src/type/composite/composite.ts b/src/type/composite/composite.ts index 0c6abe8a0..dfc9f6e8d 100644 --- a/src/type/composite/composite.ts +++ b/src/type/composite/composite.ts @@ -40,13 +40,13 @@ import { CloneType } from '../clone/type' // prettier-ignore type CompositeKeys = T extends [infer L extends TObject, ...infer R extends TObject[]] - ? keyof L['properties'] | CompositeKeys - : never + ? keyof L['properties'] | CompositeKeys + : never // prettier-ignore type CompositeIndex, K extends string[]> = K extends [infer L extends string, ...infer R extends string[]] - ? { [_ in L]: IndexedTypeResolve } & CompositeIndex - : {} + ? { [_ in L]: IndexedTypeResolve } & CompositeIndex + : {} // prettier-ignore type CompositeReduce = UnionToTuple> extends infer K ? Evaluate, Assert>> @@ -67,6 +67,6 @@ export function CompositeResolve(T: [...T]): CompositeResol export type TComposite = CompositeResolve /** `[Json]` Creates a Composite object type */ -export function Composite(T: [...T], options?: ObjectOptions): CompositeResolve { - return CloneType(CompositeResolve(T) as TObject, options) as CompositeResolve +export function Composite(T: [...T], options?: ObjectOptions): TComposite { + return CloneType(CompositeResolve(T) as TObject, options) as TComposite } diff --git a/src/type/const/const.ts b/src/type/const/const.ts index ccd6bc9b9..515c81c10 100644 --- a/src/type/const/const.ts +++ b/src/type/const/const.ts @@ -26,7 +26,7 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import type { AssertProperties, AssertRest, Evaluate } from '../helpers/index' +import type { AssertProperties, AssertRest, AssertType, Evaluate } from '../helpers/index' import type { TSchema, SchemaOptions } from '../schema/index' import type { TProperties } from '../object/index' import { IsArray, IsNumber, IsBigInt, IsUint8Array, IsDate, IsIterator, IsObject, IsAsyncIterator, IsFunction, IsUndefined, IsNull, IsSymbol, IsBoolean, IsString } from '../guard/value' @@ -52,7 +52,7 @@ import { TypeClone } from '../clone/index' // ------------------------------------------------------------------ // prettier-ignore type FromArray = - T extends readonly [infer L, ...infer R] + T extends readonly [infer L extends unknown, ...infer R extends unknown[]] ? [FromValue, ...FromArray] : T // prettier-ignore @@ -60,7 +60,7 @@ function FromArray(T: [...T]): FromArray { const [L, ...R] = T return ( T.length > 0 - ? [FromValue(L), ...FromArray(R)] + ? [FromValue(L) as TSchema, ...FromArray(R)] : [] ) as FromArray } @@ -69,7 +69,9 @@ function FromArray(T: [...T]): FromArray { // ------------------------------------------------------------------ // prettier-ignore type FromProperties> = { - -readonly [K in keyof T]: TReadonly> + -readonly [K in keyof T]: FromValue extends infer R extends TSchema + ? TReadonly + : TReadonly } // prettier-ignore function FromProperties>(value: T): FromProperties { @@ -103,7 +105,7 @@ function FromValue(value: T): FromValue { IsArray(value) ? Tuple(FromArray(value) as TSchema[]) : IsUint8Array(value) ? Uint8Array() : IsDate(value) ? Date() : - IsObject(value) ? Object(FromProperties(value) as TProperties) : + IsObject(value) ? Object(FromProperties(value as Record) as TProperties) : IsAsyncIterator(value) ? AsyncIterator(Unknown()) : IsIterator(value) ? Iterator(Unknown()) : IsFunction(value) ? Function([], Unknown()) : @@ -115,7 +117,7 @@ function FromValue(value: T): FromValue { IsBoolean(value) ? Literal(value) : IsString(value) ? Literal(value) : Never() - ) as unknown as FromValue + ) as FromValue } // ------------------------------------------------------------------ // TConst