Skip to content

Commit

Permalink
Revision 0.32.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 29, 2023
1 parent d2955b3 commit 3afe0ce
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/type/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ import * as TypeBuilder from './type'
import { JavaScriptTypeBuilder } from './javascript'

/** JavaScript Type Builder with Static Resolution for TypeScript */
const Type: InstanceType<typeof JavaScriptTypeBuilder> = TypeBuilder
const Type = TypeBuilder as InstanceType<typeof JavaScriptTypeBuilder>
export { JavaScriptTypeBuilder }
export { Type }
2 changes: 1 addition & 1 deletion src/type/builder/json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class JsonTypeBuilder {
}
/** `[Json]` Creates a Composite object type */
public Composite<T extends TObject[]>(objects: [...T], options?: ObjectOptions): TComposite<T> {
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<T extends TSchema>(schema: T, references: TSchema[]): TDeref<T> {
Expand Down
12 changes: 6 additions & 6 deletions src/type/composite/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ import { CloneType } from '../clone/type'
// prettier-ignore
type CompositeKeys<T extends TObject[]> =
T extends [infer L extends TObject, ...infer R extends TObject[]]
? keyof L['properties'] | CompositeKeys<R>
: never
? keyof L['properties'] | CompositeKeys<R>
: never
// prettier-ignore
type CompositeIndex<T extends TIntersect<TObject[]>, K extends string[]> =
K extends [infer L extends string, ...infer R extends string[]]
? { [_ in L]: IndexedTypeResolve<T, [L]> } & CompositeIndex<T, R>
: {}
? { [_ in L]: IndexedTypeResolve<T, [L]> } & CompositeIndex<T, R>
: {}
// prettier-ignore
type CompositeReduce<T extends TObject[]> = UnionToTuple<CompositeKeys<T>> extends infer K
? Evaluate<CompositeIndex<TIntersect<T>, Assert<K, string[]>>>
Expand All @@ -67,6 +67,6 @@ export function CompositeResolve<T extends TObject[]>(T: [...T]): CompositeResol
export type TComposite<T extends TObject[]> = CompositeResolve<T>

/** `[Json]` Creates a Composite object type */
export function Composite<T extends TObject[]>(T: [...T], options?: ObjectOptions): CompositeResolve<T> {
return CloneType(CompositeResolve(T) as TObject, options) as CompositeResolve<T>
export function Composite<T extends TObject[]>(T: [...T], options?: ObjectOptions): TComposite<T> {
return CloneType(CompositeResolve(T) as TObject, options) as TComposite<T>
}
14 changes: 8 additions & 6 deletions src/type/const/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -52,15 +52,15 @@ import { TypeClone } from '../clone/index'
// ------------------------------------------------------------------
// prettier-ignore
type FromArray<T extends readonly unknown[]> =
T extends readonly [infer L, ...infer R]
T extends readonly [infer L extends unknown, ...infer R extends unknown[]]
? [FromValue<L>, ...FromArray<R>]
: T
// prettier-ignore
function FromArray<T extends readonly unknown[]>(T: [...T]): FromArray<T> {
const [L, ...R] = T
return (
T.length > 0
? [FromValue(L), ...FromArray(R)]
? [FromValue(L) as TSchema, ...FromArray(R)]
: []
) as FromArray<T>
}
Expand All @@ -69,7 +69,9 @@ function FromArray<T extends readonly unknown[]>(T: [...T]): FromArray<T> {
// ------------------------------------------------------------------
// prettier-ignore
type FromProperties<T extends Record<PropertyKey, unknown>> = {
-readonly [K in keyof T]: TReadonly<FromValue<T[K]>>
-readonly [K in keyof T]: FromValue<T[K]> extends infer R extends TSchema
? TReadonly<R>
: TReadonly<TNever>
}
// prettier-ignore
function FromProperties<T extends Record<PropertyKey, unknown>>(value: T): FromProperties<T> {
Expand Down Expand Up @@ -103,7 +105,7 @@ function FromValue<T>(value: T): FromValue<T> {
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<PropertyKey, unknown>) as TProperties) :
IsAsyncIterator(value) ? AsyncIterator(Unknown()) :
IsIterator(value) ? Iterator(Unknown()) :
IsFunction(value) ? Function([], Unknown()) :
Expand All @@ -115,7 +117,7 @@ function FromValue<T>(value: T): FromValue<T> {
IsBoolean(value) ? Literal(value) :
IsString(value) ? Literal(value) :
Never()
) as unknown as FromValue<T>
) as FromValue<T>
}
// ------------------------------------------------------------------
// TConst
Expand Down

0 comments on commit 3afe0ce

Please sign in to comment.