@sinclair/typebox 0.34.41 → 0.34.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ type TCompositeProperty<T extends TSchema[], K extends PropertyKey, Acc extends
12
12
  type TCompositeProperties<T extends TSchema[], K extends PropertyKey[], Acc = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TCompositeProperties<T, R, Acc & {
13
13
  [_ in L]: TIntersectEvaluated<TCompositeProperty<T, L>>;
14
14
  }> : Acc);
15
- type TCompositeEvaluate<T extends TSchema[], K extends PropertyKey[] = TCompositeKeys<T>, P extends TProperties = Evaluate<TCompositeProperties<T, K>>, R extends TObject = TObject<P>> = R;
15
+ type TCompositeEvaluate<T extends TSchema[], K extends PropertyKey[] = TCompositeKeys<T>, P extends TProperties = Evaluate<TCompositeProperties<T, K>>, R extends TSchema = TObject<P>> = R;
16
16
  export type TComposite<T extends TSchema[]> = TCompositeEvaluate<T>;
17
17
  export declare function Composite<T extends TSchema[]>(T: [...T], options?: ObjectOptions): TComposite<T>;
18
18
  export {};
@@ -24,7 +24,7 @@ type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TAr
24
24
  type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
25
25
  type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
26
26
  type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
27
- type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends TObject = TObject<MappedProperties>> = Result;
27
+ type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
28
28
  type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
29
29
  type TFromArgument<Args extends TSchema[], Index extends number, Result extends TSchema = Index extends keyof Args[Index] ? Args[Index] : TUnknown> = Result;
30
30
  type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
@@ -1,6 +1,6 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index';
2
2
  import type { Static } from '../static/index';
3
- import type { Evaluate } from '../helpers/index';
3
+ import type { Evaluate, UnionToTuple } from '../helpers/index';
4
4
  import type { TReadonly } from '../readonly/index';
5
5
  import type { TOptional } from '../optional/index';
6
6
  import { Kind } from '../symbols/index';
@@ -20,6 +20,10 @@ type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProp
20
20
  }>;
21
21
  export type TPropertyKey = string | number;
22
22
  export type TProperties = Record<TPropertyKey, TSchema>;
23
+ /** Creates a RequiredArray derived from the given TProperties value. */
24
+ type TRequiredArray<Properties extends TProperties, RequiredProperties extends TProperties = {
25
+ [Key in keyof Properties as Properties[Key] extends TOptional<Properties[Key]> ? never : Key]: Properties[Key];
26
+ }, RequiredKeys extends string[] = UnionToTuple<Extract<keyof RequiredProperties, string>>, Result extends string[] | undefined = RequiredKeys extends [] ? undefined : RequiredKeys> = Result;
23
27
  export type TAdditionalProperties = undefined | TSchema | boolean;
24
28
  export interface ObjectOptions extends SchemaOptions {
25
29
  /** Additional property constraints for this object */
@@ -35,7 +39,7 @@ export interface TObject<T extends TProperties = TProperties> extends TSchema, O
35
39
  additionalProperties?: TAdditionalProperties;
36
40
  type: 'object';
37
41
  properties: T;
38
- required?: string[];
42
+ required: TRequiredArray<T>;
39
43
  }
40
44
  /** `[Json]` Creates an Object type */
41
45
  declare function _Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
@@ -8,19 +8,15 @@ const index_1 = require("../symbols/index");
8
8
  // TypeGuard
9
9
  // ------------------------------------------------------------------
10
10
  const kind_1 = require("../guard/kind");
11
- function RequiredKeys(properties) {
12
- const keys = [];
13
- for (let key in properties) {
14
- if (!(0, kind_1.IsOptional)(properties[key]))
15
- keys.push(key);
16
- }
17
- return keys;
11
+ /** Creates a RequiredArray derived from the given TProperties value. */
12
+ function RequiredArray(properties) {
13
+ return globalThis.Object.keys(properties).filter((key) => !(0, kind_1.IsOptional)(properties[key]));
18
14
  }
19
15
  /** `[Json]` Creates an Object type */
20
16
  function _Object(properties, options) {
21
- const required = RequiredKeys(properties);
22
- const schematic = required.length > 0 ? { [index_1.Kind]: 'Object', type: 'object', properties, required } : { [index_1.Kind]: 'Object', type: 'object', properties };
23
- return (0, type_1.CreateType)(schematic, options);
17
+ const required = RequiredArray(properties);
18
+ const schema = required.length > 0 ? { [index_1.Kind]: 'Object', type: 'object', required, properties } : { [index_1.Kind]: 'Object', type: 'object', properties };
19
+ return (0, type_1.CreateType)(schema, options);
24
20
  }
25
21
  /** `[Json]` Creates an Object type */
26
22
  exports.Object = _Object;
@@ -1,5 +1,5 @@
1
1
  import type { SchemaOptions, TSchema } from '../schema/index';
2
- import type { TupleToUnion, Evaluate, Ensure } from '../helpers/index';
2
+ import type { TupleToUnion, Evaluate } from '../helpers/index';
3
3
  import { type TRecursive } from '../recursive/index';
4
4
  import type { TMappedKey, TMappedResult } from '../mapped/index';
5
5
  import { TComputed } from '../computed/index';
@@ -14,9 +14,9 @@ import { type TOmitFromMappedResult } from './omit-from-mapped-result';
14
14
  type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TOmit<L, PropertyKeys>]> : Result);
15
15
  type TFromUnion<T extends TSchema[], K extends PropertyKey[], Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, K, [...Result, TOmit<L, K>]> : Result);
16
16
  type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKey extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Omit<Properties, UnionKey>>);
17
- type TFromObject<Type extends TObject, PropertyKeys extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties, PropertyKeys>)>>;
17
+ type TFromObject<_Type extends TObject, PropertyKeys extends PropertyKey[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties, PropertyKeys>, Result extends TSchema = TObject<MappedProperties>> = Result;
18
18
  type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
19
- export type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject<TObject<Types>, PropertyKeys> : TObject<{}>);
19
+ export type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, PropertyKeys, Properties> : TObject<{}>);
20
20
  type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
21
21
  type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
22
22
  export type TOmit<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TOmitFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TOmitFromMappedKey<Type, Key> : [
@@ -42,10 +42,10 @@ function FromProperties(properties, propertyKeys) {
42
42
  return propertyKeys.reduce((T, K2) => FromProperty(T, K2), properties);
43
43
  }
44
44
  // prettier-ignore
45
- function FromObject(properties, propertyKeys) {
46
- const options = (0, discard_1.Discard)(properties, [symbols_1.TransformKind, '$id', 'required', 'properties']);
47
- const omittedProperties = FromProperties(properties['properties'], propertyKeys);
48
- return (0, index_6.Object)(omittedProperties, options);
45
+ function FromObject(type, propertyKeys, properties) {
46
+ const options = (0, discard_1.Discard)(type, [symbols_1.TransformKind, '$id', 'required', 'properties']);
47
+ const mappedProperties = FromProperties(properties, propertyKeys);
48
+ return (0, index_6.Object)(mappedProperties, options);
49
49
  }
50
50
  // prettier-ignore
51
51
  function UnionFromPropertyKeys(propertyKeys) {
@@ -53,10 +53,10 @@ function UnionFromPropertyKeys(propertyKeys) {
53
53
  return (0, index_5.Union)(result);
54
54
  }
55
55
  // prettier-ignore
56
- function OmitResolve(properties, propertyKeys) {
57
- return ((0, kind_1.IsIntersect)(properties) ? (0, index_4.Intersect)(FromIntersect(properties.allOf, propertyKeys)) :
58
- (0, kind_1.IsUnion)(properties) ? (0, index_5.Union)(FromUnion(properties.anyOf, propertyKeys)) :
59
- (0, kind_1.IsObject)(properties) ? FromObject(properties, propertyKeys) :
56
+ function OmitResolve(type, propertyKeys) {
57
+ return ((0, kind_1.IsIntersect)(type) ? (0, index_4.Intersect)(FromIntersect(type.allOf, propertyKeys)) :
58
+ (0, kind_1.IsUnion)(type) ? (0, index_5.Union)(FromUnion(type.anyOf, propertyKeys)) :
59
+ (0, kind_1.IsObject)(type) ? FromObject(type, propertyKeys, type.properties) :
60
60
  (0, index_6.Object)({}));
61
61
  }
62
62
  /** `[Json]` Constructs a type whose keys are picked from the given type */
@@ -25,9 +25,9 @@ type TFromRef<Ref extends string> = Ensure<TComputed<'Partial', [TRef<Ref>]>>;
25
25
  type TFromProperties<Properties extends TProperties> = Evaluate<{
26
26
  [K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<Properties[K]>;
27
27
  }>;
28
- type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
28
+ type TFromObject<_Type extends TObject, Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
29
29
  type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TPartial<L>]> : Result);
30
- export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
30
+ export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, Properties> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
31
31
  /** `[Json]` Constructs a type where all properties are optional */
32
32
  export declare function Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
33
33
  /** `[Json]` Constructs a type where all properties are optional */
@@ -65,10 +65,10 @@ function FromProperties(properties) {
65
65
  return partialProperties;
66
66
  }
67
67
  // prettier-ignore
68
- function FromObject(type) {
68
+ function FromObject(type, properties) {
69
69
  const options = (0, index_7.Discard)(type, [index_8.TransformKind, '$id', 'required', 'properties']);
70
- const properties = FromProperties(type['properties']);
71
- return (0, index_3.Object)(properties, options);
70
+ const mappedProperties = FromProperties(properties);
71
+ return (0, index_3.Object)(mappedProperties, options);
72
72
  }
73
73
  // prettier-ignore
74
74
  function FromRest(types) {
@@ -85,7 +85,7 @@ function PartialResolve(type) {
85
85
  KindGuard.IsRef(type) ? FromRef(type.$ref) :
86
86
  KindGuard.IsIntersect(type) ? (0, index_4.Intersect)(FromRest(type.allOf)) :
87
87
  KindGuard.IsUnion(type) ? (0, index_5.Union)(FromRest(type.anyOf)) :
88
- KindGuard.IsObject(type) ? FromObject(type) :
88
+ KindGuard.IsObject(type) ? FromObject(type, type.properties) :
89
89
  // Intrinsic
90
90
  KindGuard.IsBigInt(type) ? type :
91
91
  KindGuard.IsBoolean(type) ? type :
@@ -1,5 +1,5 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index';
2
- import type { TupleToUnion, Evaluate, Ensure } from '../helpers/index';
2
+ import type { TupleToUnion, Evaluate } from '../helpers/index';
3
3
  import { type TRecursive } from '../recursive/index';
4
4
  import { type TComputed } from '../computed/index';
5
5
  import { type TIntersect } from '../intersect/index';
@@ -14,9 +14,9 @@ import { type TPickFromMappedResult } from './pick-from-mapped-result';
14
14
  type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
15
15
  type TFromUnion<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
16
16
  type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKeys extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Pick<Properties, UnionKeys & keyof Properties>>);
17
- type TFromObject<Type extends TObject, Key extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties, Key>)>>;
17
+ type TFromObject<_Type extends TObject, Keys extends PropertyKey[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties, Keys>, Result extends TSchema = TObject<MappedProperties>> = Result;
18
18
  type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
19
- export type TPickResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TPickResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject<TObject<Types>, PropertyKeys> : TObject<{}>);
19
+ export type TPickResolve<Type extends TProperties, PropertyKeys extends PropertyKey[]> = (Type extends TRecursive<infer Types extends TSchema> ? TRecursive<TPickResolve<Types, PropertyKeys>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, PropertyKeys, Properties> : TObject<{}>);
20
20
  type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
21
21
  type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
22
22
  export type TPick<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TPickFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TPickFromMappedKey<Type, Key> : [
@@ -37,10 +37,10 @@ function FromProperties(properties, propertyKeys) {
37
37
  return result;
38
38
  }
39
39
  // prettier-ignore
40
- function FromObject(T, K) {
41
- const options = (0, discard_1.Discard)(T, [symbols_1.TransformKind, '$id', 'required', 'properties']);
42
- const properties = FromProperties(T['properties'], K);
43
- return (0, index_4.Object)(properties, options);
40
+ function FromObject(Type, keys, properties) {
41
+ const options = (0, discard_1.Discard)(Type, [symbols_1.TransformKind, '$id', 'required', 'properties']);
42
+ const mappedProperties = FromProperties(properties, keys);
43
+ return (0, index_4.Object)(mappedProperties, options);
44
44
  }
45
45
  // prettier-ignore
46
46
  function UnionFromPropertyKeys(propertyKeys) {
@@ -48,10 +48,10 @@ function UnionFromPropertyKeys(propertyKeys) {
48
48
  return (0, index_5.Union)(result);
49
49
  }
50
50
  // prettier-ignore
51
- function PickResolve(properties, propertyKeys) {
52
- return ((0, kind_1.IsIntersect)(properties) ? (0, index_2.Intersect)(FromIntersect(properties.allOf, propertyKeys)) :
53
- (0, kind_1.IsUnion)(properties) ? (0, index_5.Union)(FromUnion(properties.anyOf, propertyKeys)) :
54
- (0, kind_1.IsObject)(properties) ? FromObject(properties, propertyKeys) :
51
+ function PickResolve(type, propertyKeys) {
52
+ return ((0, kind_1.IsIntersect)(type) ? (0, index_2.Intersect)(FromIntersect(type.allOf, propertyKeys)) :
53
+ (0, kind_1.IsUnion)(type) ? (0, index_5.Union)(FromUnion(type.anyOf, propertyKeys)) :
54
+ (0, kind_1.IsObject)(type) ? FromObject(type, propertyKeys, type.properties) :
55
55
  (0, index_4.Object)({}));
56
56
  }
57
57
  /** `[Json]` Constructs a type whose keys are picked from the given type */
@@ -25,9 +25,9 @@ type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
25
25
  type TFromProperties<Properties extends TProperties> = Evaluate<{
26
26
  [K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonly<S> : Properties[K] extends (TOptional<infer S>) ? S : Properties[K];
27
27
  }>;
28
- type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
28
+ type TFromObject<_Type extends TObject, Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
29
29
  type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TRequired<L>]> : Result);
30
- export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
30
+ export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, Properties> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
31
31
  /** `[Json]` Constructs a type where all properties are required */
32
32
  export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
33
33
  /** `[Json]` Constructs a type where all properties are required */
@@ -64,10 +64,10 @@ function FromProperties(properties) {
64
64
  return requiredProperties;
65
65
  }
66
66
  // prettier-ignore
67
- function FromObject(type) {
67
+ function FromObject(type, properties) {
68
68
  const options = (0, index_7.Discard)(type, [index_6.TransformKind, '$id', 'required', 'properties']);
69
- const properties = FromProperties(type['properties']);
70
- return (0, index_2.Object)(properties, options);
69
+ const mappedProperties = FromProperties(properties);
70
+ return (0, index_2.Object)(mappedProperties, options);
71
71
  }
72
72
  // prettier-ignore
73
73
  function FromRest(types) {
@@ -84,7 +84,7 @@ function RequiredResolve(type) {
84
84
  KindGuard.IsRef(type) ? FromRef(type.$ref) :
85
85
  KindGuard.IsIntersect(type) ? (0, index_3.Intersect)(FromRest(type.allOf)) :
86
86
  KindGuard.IsUnion(type) ? (0, index_4.Union)(FromRest(type.anyOf)) :
87
- KindGuard.IsObject(type) ? FromObject(type) :
87
+ KindGuard.IsObject(type) ? FromObject(type, type.properties) :
88
88
  // Intrinsic
89
89
  KindGuard.IsBigInt(type) ? type :
90
90
  KindGuard.IsBoolean(type) ? type :
@@ -6,10 +6,10 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
6
6
  [Kind]: 'Tuple';
7
7
  static: TupleStatic<T, this['params']>;
8
8
  type: 'array';
9
- items?: T;
9
+ items: T;
10
10
  additionalItems?: false;
11
- minItems: number;
12
- maxItems: number;
11
+ minItems: T['length'];
12
+ maxItems: T['length'];
13
13
  }
14
14
  /** `[Json]` Creates a Tuple type */
15
15
  export declare function Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;
@@ -12,7 +12,7 @@ type TCompositeProperty<T extends TSchema[], K extends PropertyKey, Acc extends
12
12
  type TCompositeProperties<T extends TSchema[], K extends PropertyKey[], Acc = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TCompositeProperties<T, R, Acc & {
13
13
  [_ in L]: TIntersectEvaluated<TCompositeProperty<T, L>>;
14
14
  }> : Acc);
15
- type TCompositeEvaluate<T extends TSchema[], K extends PropertyKey[] = TCompositeKeys<T>, P extends TProperties = Evaluate<TCompositeProperties<T, K>>, R extends TObject = TObject<P>> = R;
15
+ type TCompositeEvaluate<T extends TSchema[], K extends PropertyKey[] = TCompositeKeys<T>, P extends TProperties = Evaluate<TCompositeProperties<T, K>>, R extends TSchema = TObject<P>> = R;
16
16
  export type TComposite<T extends TSchema[]> = TCompositeEvaluate<T>;
17
17
  export declare function Composite<T extends TSchema[]>(T: [...T], options?: ObjectOptions): TComposite<T>;
18
18
  export {};
@@ -24,7 +24,7 @@ type TFromArray<Args extends TSchema[], Type extends TSchema, Result extends TAr
24
24
  type TFromAsyncIterator<Args extends TSchema[], Type extends TSchema, Result extends TAsyncIterator = TAsyncIterator<TFromType<Args, Type>>> = Result;
25
25
  type TFromIterator<Args extends TSchema[], Type extends TSchema, Result extends TIterator = TIterator<TFromType<Args, Type>>> = Result;
26
26
  type TFromPromise<Args extends TSchema[], Type extends TSchema, Result extends TPromise = TPromise<TFromType<Args, Type>>> = Result;
27
- type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends TObject = TObject<MappedProperties>> = Result;
27
+ type TFromObject<Args extends TSchema[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Args, Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
28
28
  type TFromRecord<Args extends TSchema[], Key extends TSchema, Value extends TSchema, MappedKey extends TSchema = TFromType<Args, Key>, MappedValue extends TSchema = TFromType<Args, Value>, Result extends TSchema = TRecordOrObject<MappedKey, MappedValue>> = Result;
29
29
  type TFromArgument<Args extends TSchema[], Index extends number, Result extends TSchema = Index extends keyof Args[Index] ? Args[Index] : TUnknown> = Result;
30
30
  type TFromProperty<Args extends TSchema[], Type extends TSchema, IsReadonly extends boolean = Type extends TReadonly<Type> ? true : false, IsOptional extends boolean = Type extends TOptional<Type> ? true : false, Mapped extends TSchema = TFromType<Args, Type>, Result extends TSchema = ([
@@ -1,6 +1,6 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
2
  import type { Static } from '../static/index.mjs';
3
- import type { Evaluate } from '../helpers/index.mjs';
3
+ import type { Evaluate, UnionToTuple } from '../helpers/index.mjs';
4
4
  import type { TReadonly } from '../readonly/index.mjs';
5
5
  import type { TOptional } from '../optional/index.mjs';
6
6
  import { Kind } from '../symbols/index.mjs';
@@ -20,6 +20,10 @@ type ObjectStatic<T extends TProperties, P extends unknown[]> = ObjectStaticProp
20
20
  }>;
21
21
  export type TPropertyKey = string | number;
22
22
  export type TProperties = Record<TPropertyKey, TSchema>;
23
+ /** Creates a RequiredArray derived from the given TProperties value. */
24
+ type TRequiredArray<Properties extends TProperties, RequiredProperties extends TProperties = {
25
+ [Key in keyof Properties as Properties[Key] extends TOptional<Properties[Key]> ? never : Key]: Properties[Key];
26
+ }, RequiredKeys extends string[] = UnionToTuple<Extract<keyof RequiredProperties, string>>, Result extends string[] | undefined = RequiredKeys extends [] ? undefined : RequiredKeys> = Result;
23
27
  export type TAdditionalProperties = undefined | TSchema | boolean;
24
28
  export interface ObjectOptions extends SchemaOptions {
25
29
  /** Additional property constraints for this object */
@@ -35,7 +39,7 @@ export interface TObject<T extends TProperties = TProperties> extends TSchema, O
35
39
  additionalProperties?: TAdditionalProperties;
36
40
  type: 'object';
37
41
  properties: T;
38
- required?: string[];
42
+ required: TRequiredArray<T>;
39
43
  }
40
44
  /** `[Json]` Creates an Object type */
41
45
  declare function _Object<T extends TProperties>(properties: T, options?: ObjectOptions): TObject<T>;
@@ -4,19 +4,15 @@ import { Kind } from '../symbols/index.mjs';
4
4
  // TypeGuard
5
5
  // ------------------------------------------------------------------
6
6
  import { IsOptional } from '../guard/kind.mjs';
7
- function RequiredKeys(properties) {
8
- const keys = [];
9
- for (let key in properties) {
10
- if (!IsOptional(properties[key]))
11
- keys.push(key);
12
- }
13
- return keys;
7
+ /** Creates a RequiredArray derived from the given TProperties value. */
8
+ function RequiredArray(properties) {
9
+ return globalThis.Object.keys(properties).filter((key) => !IsOptional(properties[key]));
14
10
  }
15
11
  /** `[Json]` Creates an Object type */
16
12
  function _Object(properties, options) {
17
- const required = RequiredKeys(properties);
18
- const schematic = required.length > 0 ? { [Kind]: 'Object', type: 'object', properties, required } : { [Kind]: 'Object', type: 'object', properties };
19
- return CreateType(schematic, options);
13
+ const required = RequiredArray(properties);
14
+ const schema = required.length > 0 ? { [Kind]: 'Object', type: 'object', required, properties } : { [Kind]: 'Object', type: 'object', properties };
15
+ return CreateType(schema, options);
20
16
  }
21
17
  /** `[Json]` Creates an Object type */
22
18
  export var Object = _Object;
@@ -1,5 +1,5 @@
1
1
  import type { SchemaOptions, TSchema } from '../schema/index.mjs';
2
- import type { TupleToUnion, Evaluate, Ensure } from '../helpers/index.mjs';
2
+ import type { TupleToUnion, Evaluate } from '../helpers/index.mjs';
3
3
  import { type TRecursive } from '../recursive/index.mjs';
4
4
  import type { TMappedKey, TMappedResult } from '../mapped/index.mjs';
5
5
  import { TComputed } from '../computed/index.mjs';
@@ -14,9 +14,9 @@ import { type TOmitFromMappedResult } from './omit-from-mapped-result.mjs';
14
14
  type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TOmit<L, PropertyKeys>]> : Result);
15
15
  type TFromUnion<T extends TSchema[], K extends PropertyKey[], Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, K, [...Result, TOmit<L, K>]> : Result);
16
16
  type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKey extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Omit<Properties, UnionKey>>);
17
- type TFromObject<Type extends TObject, PropertyKeys extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties, PropertyKeys>)>>;
17
+ type TFromObject<_Type extends TObject, PropertyKeys extends PropertyKey[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties, PropertyKeys>, Result extends TSchema = TObject<MappedProperties>> = Result;
18
18
  type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
19
- export type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject<TObject<Types>, PropertyKeys> : TObject<{}>);
19
+ export type TOmitResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TOmitResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, PropertyKeys, Properties> : TObject<{}>);
20
20
  type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
21
21
  type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
22
22
  export type TOmit<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TOmitFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TOmitFromMappedKey<Type, Key> : [
@@ -38,10 +38,10 @@ function FromProperties(properties, propertyKeys) {
38
38
  return propertyKeys.reduce((T, K2) => FromProperty(T, K2), properties);
39
39
  }
40
40
  // prettier-ignore
41
- function FromObject(properties, propertyKeys) {
42
- const options = Discard(properties, [TransformKind, '$id', 'required', 'properties']);
43
- const omittedProperties = FromProperties(properties['properties'], propertyKeys);
44
- return Object(omittedProperties, options);
41
+ function FromObject(type, propertyKeys, properties) {
42
+ const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
43
+ const mappedProperties = FromProperties(properties, propertyKeys);
44
+ return Object(mappedProperties, options);
45
45
  }
46
46
  // prettier-ignore
47
47
  function UnionFromPropertyKeys(propertyKeys) {
@@ -49,10 +49,10 @@ function UnionFromPropertyKeys(propertyKeys) {
49
49
  return Union(result);
50
50
  }
51
51
  // prettier-ignore
52
- function OmitResolve(properties, propertyKeys) {
53
- return (IsIntersect(properties) ? Intersect(FromIntersect(properties.allOf, propertyKeys)) :
54
- IsUnion(properties) ? Union(FromUnion(properties.anyOf, propertyKeys)) :
55
- IsObject(properties) ? FromObject(properties, propertyKeys) :
52
+ function OmitResolve(type, propertyKeys) {
53
+ return (IsIntersect(type) ? Intersect(FromIntersect(type.allOf, propertyKeys)) :
54
+ IsUnion(type) ? Union(FromUnion(type.anyOf, propertyKeys)) :
55
+ IsObject(type) ? FromObject(type, propertyKeys, type.properties) :
56
56
  Object({}));
57
57
  }
58
58
  /** `[Json]` Constructs a type whose keys are picked from the given type */
@@ -25,9 +25,9 @@ type TFromRef<Ref extends string> = Ensure<TComputed<'Partial', [TRef<Ref>]>>;
25
25
  type TFromProperties<Properties extends TProperties> = Evaluate<{
26
26
  [K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonlyOptional<S> : Properties[K] extends (TOptional<infer S>) ? TOptional<S> : TOptional<Properties[K]>;
27
27
  }>;
28
- type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
28
+ type TFromObject<_Type extends TObject, Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
29
29
  type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TPartial<L>]> : Result);
30
- export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
30
+ export type TPartial<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TPartial<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, Properties> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
31
31
  /** `[Json]` Constructs a type where all properties are optional */
32
32
  export declare function Partial<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TPartialFromMappedResult<MappedResult>;
33
33
  /** `[Json]` Constructs a type where all properties are optional */
@@ -28,10 +28,10 @@ function FromProperties(properties) {
28
28
  return partialProperties;
29
29
  }
30
30
  // prettier-ignore
31
- function FromObject(type) {
31
+ function FromObject(type, properties) {
32
32
  const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
33
- const properties = FromProperties(type['properties']);
34
- return Object(properties, options);
33
+ const mappedProperties = FromProperties(properties);
34
+ return Object(mappedProperties, options);
35
35
  }
36
36
  // prettier-ignore
37
37
  function FromRest(types) {
@@ -48,7 +48,7 @@ function PartialResolve(type) {
48
48
  KindGuard.IsRef(type) ? FromRef(type.$ref) :
49
49
  KindGuard.IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
50
50
  KindGuard.IsUnion(type) ? Union(FromRest(type.anyOf)) :
51
- KindGuard.IsObject(type) ? FromObject(type) :
51
+ KindGuard.IsObject(type) ? FromObject(type, type.properties) :
52
52
  // Intrinsic
53
53
  KindGuard.IsBigInt(type) ? type :
54
54
  KindGuard.IsBoolean(type) ? type :
@@ -1,5 +1,5 @@
1
1
  import type { TSchema, SchemaOptions } from '../schema/index.mjs';
2
- import type { TupleToUnion, Evaluate, Ensure } from '../helpers/index.mjs';
2
+ import type { TupleToUnion, Evaluate } from '../helpers/index.mjs';
3
3
  import { type TRecursive } from '../recursive/index.mjs';
4
4
  import { type TComputed } from '../computed/index.mjs';
5
5
  import { type TIntersect } from '../intersect/index.mjs';
@@ -14,9 +14,9 @@ import { type TPickFromMappedResult } from './pick-from-mapped-result.mjs';
14
14
  type TFromIntersect<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromIntersect<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
15
15
  type TFromUnion<Types extends TSchema[], PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, PropertyKeys, [...Result, TPick<L, PropertyKeys>]> : Result;
16
16
  type TFromProperties<Properties extends TProperties, PropertyKeys extends PropertyKey[], UnionKeys extends PropertyKey = TupleToUnion<PropertyKeys>> = (Evaluate<Pick<Properties, UnionKeys & keyof Properties>>);
17
- type TFromObject<Type extends TObject, Key extends PropertyKey[], Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties, Key>)>>;
17
+ type TFromObject<_Type extends TObject, Keys extends PropertyKey[], Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties, Keys>, Result extends TSchema = TObject<MappedProperties>> = Result;
18
18
  type TUnionFromPropertyKeys<PropertyKeys extends PropertyKey[], Result extends TLiteral[] = []> = (PropertyKeys extends [infer Key extends PropertyKey, ...infer Rest extends PropertyKey[]] ? Key extends TLiteralValue ? TUnionFromPropertyKeys<Rest, [...Result, TLiteral<Key>]> : TUnionFromPropertyKeys<Rest, [...Result]> : TUnion<Result>);
19
- export type TPickResolve<Properties extends TProperties, PropertyKeys extends PropertyKey[]> = (Properties extends TRecursive<infer Types extends TSchema> ? TRecursive<TPickResolve<Types, PropertyKeys>> : Properties extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Properties extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Properties extends TObject<infer Types extends TProperties> ? TFromObject<TObject<Types>, PropertyKeys> : TObject<{}>);
19
+ export type TPickResolve<Type extends TProperties, PropertyKeys extends PropertyKey[]> = (Type extends TRecursive<infer Types extends TSchema> ? TRecursive<TPickResolve<Types, PropertyKeys>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromIntersect<Types, PropertyKeys>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromUnion<Types, PropertyKeys>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, PropertyKeys, Properties> : TObject<{}>);
20
20
  type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
21
21
  type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
22
22
  export type TPick<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Type extends TMappedResult ? TPickFromMappedResult<Type, TResolvePropertyKeys<Key>> : Key extends TMappedKey ? TPickFromMappedKey<Type, Key> : [
@@ -33,10 +33,10 @@ function FromProperties(properties, propertyKeys) {
33
33
  return result;
34
34
  }
35
35
  // prettier-ignore
36
- function FromObject(T, K) {
37
- const options = Discard(T, [TransformKind, '$id', 'required', 'properties']);
38
- const properties = FromProperties(T['properties'], K);
39
- return Object(properties, options);
36
+ function FromObject(Type, keys, properties) {
37
+ const options = Discard(Type, [TransformKind, '$id', 'required', 'properties']);
38
+ const mappedProperties = FromProperties(properties, keys);
39
+ return Object(mappedProperties, options);
40
40
  }
41
41
  // prettier-ignore
42
42
  function UnionFromPropertyKeys(propertyKeys) {
@@ -44,10 +44,10 @@ function UnionFromPropertyKeys(propertyKeys) {
44
44
  return Union(result);
45
45
  }
46
46
  // prettier-ignore
47
- function PickResolve(properties, propertyKeys) {
48
- return (IsIntersect(properties) ? Intersect(FromIntersect(properties.allOf, propertyKeys)) :
49
- IsUnion(properties) ? Union(FromUnion(properties.anyOf, propertyKeys)) :
50
- IsObject(properties) ? FromObject(properties, propertyKeys) :
47
+ function PickResolve(type, propertyKeys) {
48
+ return (IsIntersect(type) ? Intersect(FromIntersect(type.allOf, propertyKeys)) :
49
+ IsUnion(type) ? Union(FromUnion(type.anyOf, propertyKeys)) :
50
+ IsObject(type) ? FromObject(type, propertyKeys, type.properties) :
51
51
  Object({}));
52
52
  }
53
53
  /** `[Json]` Constructs a type whose keys are picked from the given type */
@@ -25,9 +25,9 @@ type TFromRef<Ref extends string> = Ensure<TComputed<'Required', [TRef<Ref>]>>;
25
25
  type TFromProperties<Properties extends TProperties> = Evaluate<{
26
26
  [K in keyof Properties]: Properties[K] extends (TReadonlyOptional<infer S>) ? TReadonly<S> : Properties[K] extends (TReadonly<infer S>) ? TReadonly<S> : Properties[K] extends (TOptional<infer S>) ? S : Properties[K];
27
27
  }>;
28
- type TFromObject<Type extends TObject, Properties extends TProperties = Type['properties']> = Ensure<TObject<(TFromProperties<Properties>)>>;
28
+ type TFromObject<_Type extends TObject, Properties extends TProperties, MappedProperties extends TProperties = TFromProperties<Properties>, Result extends TSchema = TObject<MappedProperties>> = Result;
29
29
  type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Result, TRequired<L>]> : Result);
30
- export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject<Properties>> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
30
+ export type TRequired<Type extends TSchema> = (Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TRequired<Type>> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<Target, Parameters> : Type extends TRef<infer Ref extends string> ? TFromRef<Ref> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TFromRest<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TFromRest<Types>> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<TObject, Properties> : Type extends TBigInt ? Type : Type extends TBoolean ? Type : Type extends TInteger ? Type : Type extends TLiteral ? Type : Type extends TNull ? Type : Type extends TNumber ? Type : Type extends TString ? Type : Type extends TSymbol ? Type : Type extends TUndefined ? Type : TObject<{}>);
31
31
  /** `[Json]` Constructs a type where all properties are required */
32
32
  export declare function Required<MappedResult extends TMappedResult>(type: MappedResult, options?: SchemaOptions): TRequiredFromMappedResult<MappedResult>;
33
33
  /** `[Json]` Constructs a type where all properties are required */
@@ -27,10 +27,10 @@ function FromProperties(properties) {
27
27
  return requiredProperties;
28
28
  }
29
29
  // prettier-ignore
30
- function FromObject(type) {
30
+ function FromObject(type, properties) {
31
31
  const options = Discard(type, [TransformKind, '$id', 'required', 'properties']);
32
- const properties = FromProperties(type['properties']);
33
- return Object(properties, options);
32
+ const mappedProperties = FromProperties(properties);
33
+ return Object(mappedProperties, options);
34
34
  }
35
35
  // prettier-ignore
36
36
  function FromRest(types) {
@@ -47,7 +47,7 @@ function RequiredResolve(type) {
47
47
  KindGuard.IsRef(type) ? FromRef(type.$ref) :
48
48
  KindGuard.IsIntersect(type) ? Intersect(FromRest(type.allOf)) :
49
49
  KindGuard.IsUnion(type) ? Union(FromRest(type.anyOf)) :
50
- KindGuard.IsObject(type) ? FromObject(type) :
50
+ KindGuard.IsObject(type) ? FromObject(type, type.properties) :
51
51
  // Intrinsic
52
52
  KindGuard.IsBigInt(type) ? type :
53
53
  KindGuard.IsBoolean(type) ? type :
@@ -6,10 +6,10 @@ export interface TTuple<T extends TSchema[] = TSchema[]> extends TSchema {
6
6
  [Kind]: 'Tuple';
7
7
  static: TupleStatic<T, this['params']>;
8
8
  type: 'array';
9
- items?: T;
9
+ items: T;
10
10
  additionalItems?: false;
11
- minItems: number;
12
- maxItems: number;
11
+ minItems: T['length'];
12
+ maxItems: T['length'];
13
13
  }
14
14
  /** `[Json]` Creates a Tuple type */
15
15
  export declare function Tuple<Types extends TSchema[]>(types: [...Types], options?: SchemaOptions): TTuple<Types>;