@sinclair/typebox 0.34.0 → 0.34.1

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.
Files changed (146) hide show
  1. package/build/cjs/syntax/runtime.d.ts +4 -1
  2. package/build/cjs/syntax/runtime.js +3 -1
  3. package/build/cjs/syntax/static.d.ts +3 -3
  4. package/build/cjs/type/array/array.d.ts +1 -1
  5. package/build/cjs/type/awaited/awaited.d.ts +8 -3
  6. package/build/cjs/type/awaited/awaited.js +20 -20
  7. package/build/cjs/type/computed/computed.d.ts +9 -0
  8. package/build/cjs/type/computed/computed.js +10 -0
  9. package/build/cjs/type/computed/index.d.ts +1 -0
  10. package/build/cjs/type/computed/index.js +18 -0
  11. package/build/cjs/type/guard/kind.d.ts +9 -4
  12. package/build/cjs/type/guard/kind.js +10 -0
  13. package/build/cjs/type/guard/type.d.ts +6 -3
  14. package/build/cjs/type/guard/type.js +6 -0
  15. package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +6 -6
  16. package/build/cjs/type/indexed/indexed-from-mapped-key.js +10 -10
  17. package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +5 -5
  18. package/build/cjs/type/indexed/indexed-from-mapped-result.js +11 -10
  19. package/build/cjs/type/indexed/indexed-property-keys.d.ts +6 -6
  20. package/build/cjs/type/indexed/indexed-property-keys.js +14 -14
  21. package/build/cjs/type/indexed/indexed.d.ts +34 -20
  22. package/build/cjs/type/indexed/indexed.js +59 -46
  23. package/build/cjs/type/intersect/intersect-evaluated.d.ts +6 -6
  24. package/build/cjs/type/intersect/intersect-evaluated.js +16 -16
  25. package/build/cjs/type/intersect/intersect.d.ts +2 -2
  26. package/build/cjs/type/intersect/intersect.js +6 -6
  27. package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +6 -6
  28. package/build/cjs/type/keyof/keyof-from-mapped-result.js +10 -10
  29. package/build/cjs/type/keyof/keyof-property-keys.d.ts +7 -7
  30. package/build/cjs/type/keyof/keyof-property-keys.js +22 -22
  31. package/build/cjs/type/keyof/keyof.d.ts +11 -6
  32. package/build/cjs/type/keyof/keyof.js +22 -13
  33. package/build/cjs/type/module/compute.d.ts +54 -0
  34. package/build/cjs/type/module/compute.js +154 -0
  35. package/build/cjs/type/module/infer.d.ts +43 -0
  36. package/build/cjs/type/module/infer.js +3 -0
  37. package/build/cjs/type/module/module.d.ts +8 -52
  38. package/build/cjs/type/module/module.js +14 -11
  39. package/build/cjs/type/not/not.d.ts +1 -1
  40. package/build/cjs/type/not/not.js +2 -2
  41. package/build/cjs/type/omit/omit-from-mapped-key.d.ts +6 -6
  42. package/build/cjs/type/omit/omit-from-mapped-key.js +10 -12
  43. package/build/cjs/type/omit/omit-from-mapped-result.d.ts +5 -5
  44. package/build/cjs/type/omit/omit-from-mapped-result.js +10 -10
  45. package/build/cjs/type/omit/omit.d.ts +26 -14
  46. package/build/cjs/type/omit/omit.js +46 -35
  47. package/build/cjs/type/partial/partial.d.ts +11 -7
  48. package/build/cjs/type/partial/partial.js +36 -24
  49. package/build/cjs/type/pick/pick-from-mapped-key.d.ts +6 -6
  50. package/build/cjs/type/pick/pick-from-mapped-key.js +10 -10
  51. package/build/cjs/type/pick/pick-from-mapped-result.d.ts +5 -5
  52. package/build/cjs/type/pick/pick-from-mapped-result.js +10 -10
  53. package/build/cjs/type/pick/pick.d.ts +25 -15
  54. package/build/cjs/type/pick/pick.js +47 -36
  55. package/build/cjs/type/record/record.d.ts +4 -2
  56. package/build/cjs/type/record/record.js +31 -28
  57. package/build/cjs/type/required/required.d.ts +12 -8
  58. package/build/cjs/type/required/required.js +37 -25
  59. package/build/cjs/type/tuple/tuple.d.ts +1 -1
  60. package/build/cjs/type/tuple/tuple.js +4 -4
  61. package/build/cjs/type/type/javascript.d.ts +10 -10
  62. package/build/cjs/type/type/javascript.js +6 -6
  63. package/build/cjs/type/type/json.d.ts +41 -51
  64. package/build/cjs/type/type/json.js +40 -40
  65. package/build/cjs/type/union/union-evaluated.d.ts +6 -6
  66. package/build/cjs/type/union/union-evaluated.js +11 -10
  67. package/build/cjs/type/union/union.d.ts +1 -1
  68. package/build/cjs/type/union/union.js +4 -4
  69. package/build/cjs/value/check/check.js +3 -3
  70. package/build/cjs/value/transform/decode.js +7 -7
  71. package/build/cjs/value/transform/encode.js +7 -7
  72. package/build/cjs/value/transform/has.js +18 -18
  73. package/build/esm/syntax/runtime.d.mts +4 -1
  74. package/build/esm/syntax/runtime.mjs +3 -1
  75. package/build/esm/syntax/static.d.mts +3 -3
  76. package/build/esm/type/array/array.d.mts +1 -1
  77. package/build/esm/type/awaited/awaited.d.mts +8 -3
  78. package/build/esm/type/awaited/awaited.mjs +20 -20
  79. package/build/esm/type/computed/computed.d.mts +9 -0
  80. package/build/esm/type/computed/computed.mjs +6 -0
  81. package/build/esm/type/computed/index.d.mts +1 -0
  82. package/build/esm/type/computed/index.mjs +1 -0
  83. package/build/esm/type/guard/kind.d.mts +9 -4
  84. package/build/esm/type/guard/kind.mjs +8 -0
  85. package/build/esm/type/guard/type.d.mts +6 -3
  86. package/build/esm/type/guard/type.mjs +5 -0
  87. package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +6 -6
  88. package/build/esm/type/indexed/indexed-from-mapped-key.mjs +10 -10
  89. package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +5 -5
  90. package/build/esm/type/indexed/indexed-from-mapped-result.mjs +11 -10
  91. package/build/esm/type/indexed/indexed-property-keys.d.mts +6 -6
  92. package/build/esm/type/indexed/indexed-property-keys.mjs +14 -14
  93. package/build/esm/type/indexed/indexed.d.mts +34 -20
  94. package/build/esm/type/indexed/indexed.mjs +55 -42
  95. package/build/esm/type/intersect/intersect-evaluated.d.mts +6 -6
  96. package/build/esm/type/intersect/intersect-evaluated.mjs +16 -16
  97. package/build/esm/type/intersect/intersect.d.mts +2 -2
  98. package/build/esm/type/intersect/intersect.mjs +6 -6
  99. package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +6 -6
  100. package/build/esm/type/keyof/keyof-from-mapped-result.mjs +10 -10
  101. package/build/esm/type/keyof/keyof-property-keys.d.mts +7 -7
  102. package/build/esm/type/keyof/keyof-property-keys.mjs +22 -22
  103. package/build/esm/type/keyof/keyof.d.mts +11 -6
  104. package/build/esm/type/keyof/keyof.mjs +22 -13
  105. package/build/esm/type/module/compute.d.mts +54 -0
  106. package/build/esm/type/module/compute.mjs +148 -0
  107. package/build/esm/type/module/infer.d.mts +43 -0
  108. package/build/esm/type/module/infer.mjs +1 -0
  109. package/build/esm/type/module/module.d.mts +8 -52
  110. package/build/esm/type/module/module.mjs +14 -11
  111. package/build/esm/type/not/not.d.mts +1 -1
  112. package/build/esm/type/not/not.mjs +2 -2
  113. package/build/esm/type/omit/omit-from-mapped-key.d.mts +6 -6
  114. package/build/esm/type/omit/omit-from-mapped-key.mjs +10 -12
  115. package/build/esm/type/omit/omit-from-mapped-result.d.mts +5 -5
  116. package/build/esm/type/omit/omit-from-mapped-result.mjs +10 -10
  117. package/build/esm/type/omit/omit.d.mts +26 -14
  118. package/build/esm/type/omit/omit.mjs +43 -32
  119. package/build/esm/type/partial/partial.d.mts +11 -7
  120. package/build/esm/type/partial/partial.mjs +29 -17
  121. package/build/esm/type/pick/pick-from-mapped-key.d.mts +6 -6
  122. package/build/esm/type/pick/pick-from-mapped-key.mjs +10 -10
  123. package/build/esm/type/pick/pick-from-mapped-result.d.mts +5 -5
  124. package/build/esm/type/pick/pick-from-mapped-result.mjs +10 -10
  125. package/build/esm/type/pick/pick.d.mts +25 -15
  126. package/build/esm/type/pick/pick.mjs +43 -32
  127. package/build/esm/type/record/record.d.mts +4 -2
  128. package/build/esm/type/record/record.mjs +15 -12
  129. package/build/esm/type/required/required.d.mts +12 -8
  130. package/build/esm/type/required/required.mjs +33 -21
  131. package/build/esm/type/tuple/tuple.d.mts +1 -1
  132. package/build/esm/type/tuple/tuple.mjs +4 -4
  133. package/build/esm/type/type/javascript.d.mts +10 -10
  134. package/build/esm/type/type/javascript.mjs +6 -6
  135. package/build/esm/type/type/json.d.mts +41 -51
  136. package/build/esm/type/type/json.mjs +40 -40
  137. package/build/esm/type/union/union-evaluated.d.mts +6 -6
  138. package/build/esm/type/union/union-evaluated.mjs +11 -10
  139. package/build/esm/type/union/union.d.mts +1 -1
  140. package/build/esm/type/union/union.mjs +4 -4
  141. package/build/esm/value/check/check.mjs +2 -2
  142. package/build/esm/value/transform/decode.mjs +2 -2
  143. package/build/esm/value/transform/encode.mjs +2 -2
  144. package/build/esm/value/transform/has.mjs +2 -2
  145. package/package.json +1 -1
  146. package/readme.md +30 -19
@@ -12,7 +12,10 @@ export declare const Module: Runtime.Module<{
12
12
  }>;
13
13
  ModuleType: Runtime.IUnion<unknown>;
14
14
  ModuleProperties: Runtime.IUnion<Types.TProperties>;
15
- ModuleDeclaration: Runtime.ITuple<Types.TModule<Types.TProperties>>;
15
+ ModuleDeclaration: Runtime.ITuple<Types.TModule<Types.TProperties, {
16
+ [x: string]: Types.TSchema;
17
+ [x: number]: Types.TSchema;
18
+ }>>;
16
19
  Literal: Runtime.IUnion<Types.TLiteral<string> | Types.TLiteral<number> | Types.TLiteral<boolean>>;
17
20
  Keyword: Runtime.IUnion<Types.TAny | Types.TNever | Types.TString | Types.TBoolean | Types.TNumber | Types.TInteger | Types.TBigInt | Types.TNull | Types.TSymbol | Types.TUndefined | Types.TUnknown | Types.TVoid>;
18
21
  KeyOf: Runtime.IUnion<boolean>;
@@ -283,7 +283,9 @@ const FactorExtends = (Type, Extends) => {
283
283
  // prettier-ignore
284
284
  const FactorIndexArray = (Type, IndexArray) => {
285
285
  const [Left, Right] = DestructureRight(IndexArray);
286
- return (!Types.ValueGuard.IsUndefined(Right) ? (Right.length === 1 ? Types.Index(FactorIndexArray(Type, Left), Right[0]) :
286
+ return (!Types.ValueGuard.IsUndefined(Right) ? (
287
+ // note: Indexed types require reimplementation to replace `[number]` indexers
288
+ Right.length === 1 ? Types.Index(FactorIndexArray(Type, Left), Right[0]) :
287
289
  Right.length === 0 ? Types.Array(FactorIndexArray(Type, Left)) :
288
290
  Types.Never()) : Type);
289
291
  };
@@ -456,7 +456,7 @@ type Partial = Static.Tuple<[
456
456
  Static.Const<RAngle>
457
457
  ], PartialMapping>;
458
458
  interface RequiredMapping extends Static.IMapping {
459
- output: this['input'] extends ['Required', LAngle, infer Type extends Types.TSchema, RAngle] ? Types.TPartial<Type> : never;
459
+ output: this['input'] extends ['Required', LAngle, infer Type extends Types.TSchema, RAngle] ? Types.TRequired<Type> : never;
460
460
  }
461
461
  type Required = Static.Tuple<[
462
462
  Static.Const<'Required'>,
@@ -465,7 +465,7 @@ type Required = Static.Tuple<[
465
465
  Static.Const<RAngle>
466
466
  ], RequiredMapping>;
467
467
  interface PickMapping extends Static.IMapping {
468
- output: this['input'] extends ['Pick', LAngle, infer Type extends Types.TSchema, Comma, infer PropertyKey extends Types.TSchema, RAngle] ? Types.TPick<Type, Types.TIndexPropertyKeys<PropertyKey>> : never;
468
+ output: this['input'] extends ['Pick', LAngle, infer Type extends Types.TSchema, Comma, infer Key extends Types.TSchema, RAngle] ? Types.TPick<Type, Key> : never;
469
469
  }
470
470
  type Pick = Static.Tuple<[
471
471
  Static.Const<'Pick'>,
@@ -476,7 +476,7 @@ type Pick = Static.Tuple<[
476
476
  Static.Const<RAngle>
477
477
  ], PickMapping>;
478
478
  interface OmitMapping extends Static.IMapping {
479
- output: this['input'] extends ['Omit', LAngle, infer Type extends Types.TSchema, Comma, infer PropertyKey extends Types.TSchema, RAngle] ? Types.TOmit<Type, Types.TIndexPropertyKeys<PropertyKey>> : never;
479
+ output: this['input'] extends ['Omit', LAngle, infer Type extends Types.TSchema, Comma, infer Key extends Types.TSchema, RAngle] ? Types.TOmit<Type, Key> : never;
480
480
  }
481
481
  type Omit = Static.Tuple<[
482
482
  Static.Const<'Omit'>,
@@ -24,5 +24,5 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
24
24
  items: T;
25
25
  }
26
26
  /** `[Json]` Creates an Array type */
27
- export declare function Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
27
+ export declare function Array<Type extends TSchema>(items: Type, options?: ArrayOptions): TArray<Type>;
28
28
  export {};
@@ -1,9 +1,14 @@
1
+ import { Ensure } from '../helpers/index';
1
2
  import type { TSchema, SchemaOptions } from '../schema/index';
3
+ import { type TComputed } from '../computed/index';
2
4
  import { type TIntersect } from '../intersect/index';
3
5
  import { type TUnion } from '../union/index';
4
6
  import { type TPromise } from '../promise/index';
5
- type TFromRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, [...Acc, TAwaited<L>]> : Acc;
6
- export type TAwaited<T extends TSchema> = T extends TIntersect<infer S> ? TIntersect<TFromRest<S>> : T extends TUnion<infer S> ? TUnion<TFromRest<S>> : T extends TPromise<infer S> ? TAwaited<S> : T;
7
+ import { type TRef } from '../ref/index';
8
+ type TFromComputed<Target extends string, Parameters extends TSchema[]> = Ensure<(TComputed<'Awaited', [TComputed<Target, Parameters>]>)>;
9
+ type TFromRef<Ref extends string> = Ensure<TComputed<'Awaited', [TRef<Ref>]>>;
10
+ type TFromRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<Right, [...Result, TAwaited<Left>]> : Result);
11
+ export type TAwaited<Type extends TSchema> = (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 TPromise<infer Type extends TSchema> ? TAwaited<Type> : Type);
7
12
  /** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
8
- export declare function Awaited<T extends TSchema>(T: T, options?: SchemaOptions): TAwaited<T>;
13
+ export declare function Awaited<T extends TSchema>(type: T, options?: SchemaOptions): TAwaited<T>;
9
14
  export {};
@@ -2,40 +2,40 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.Awaited = Awaited;
5
- const index_1 = require("../intersect/index");
6
- const index_2 = require("../union/index");
7
5
  const type_1 = require("../create/type");
6
+ const index_1 = require("../computed/index");
7
+ const index_2 = require("../intersect/index");
8
+ const index_3 = require("../union/index");
9
+ const index_4 = require("../ref/index");
8
10
  // ------------------------------------------------------------------
9
11
  // TypeGuard
10
12
  // ------------------------------------------------------------------
11
13
  const kind_1 = require("../guard/kind");
12
14
  // prettier-ignore
13
- function FromRest(T) {
14
- return T.map(L => AwaitedResolve(L));
15
+ function FromComputed(target, parameters) {
16
+ return (0, index_1.Computed)('Awaited', [(0, index_1.Computed)(target, parameters)]);
15
17
  }
16
18
  // prettier-ignore
17
- function FromIntersect(T) {
18
- return (0, index_1.Intersect)(FromRest(T));
19
+ function FromRef($ref) {
20
+ return (0, index_1.Computed)('Awaited', [(0, index_4.Ref)($ref)]);
19
21
  }
20
22
  // prettier-ignore
21
- function FromUnion(T) {
22
- return (0, index_2.Union)(FromRest(T));
23
+ function FromIntersect(types) {
24
+ return (0, index_2.Intersect)(FromRest(types));
23
25
  }
24
26
  // prettier-ignore
25
- function FromPromise(T) {
26
- return AwaitedResolve(T);
27
+ function FromUnion(types) {
28
+ return (0, index_3.Union)(FromRest(types));
27
29
  }
28
- // ----------------------------------------------------------------
29
- // AwaitedResolve
30
- // ----------------------------------------------------------------
31
30
  // prettier-ignore
32
- function AwaitedResolve(T) {
33
- return ((0, kind_1.IsIntersect)(T) ? FromIntersect(T.allOf) :
34
- (0, kind_1.IsUnion)(T) ? FromUnion(T.anyOf) :
35
- (0, kind_1.IsPromise)(T) ? FromPromise(T.item) :
36
- T);
31
+ function FromPromise(type) {
32
+ return Awaited(type);
33
+ }
34
+ // prettier-ignore
35
+ function FromRest(types) {
36
+ return types.map(type => Awaited(type));
37
37
  }
38
38
  /** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
39
- function Awaited(T, options) {
40
- return (0, type_1.CreateType)(AwaitedResolve(T), options);
39
+ function Awaited(type, options) {
40
+ return (0, type_1.CreateType)((0, kind_1.IsComputed)(type) ? FromComputed(type.target, type.parameters) : (0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf) : (0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf) : (0, kind_1.IsPromise)(type) ? FromPromise(type.item) : (0, kind_1.IsRef)(type) ? FromRef(type.$ref) : type, options);
41
41
  }
@@ -0,0 +1,9 @@
1
+ import type { TSchema, SchemaOptions } from '../schema/index';
2
+ import { Kind } from '../symbols/symbols';
3
+ export interface TComputed<Target extends string = string, Parameters extends TSchema[] = []> extends TSchema {
4
+ [Kind]: 'Computed';
5
+ target: Target;
6
+ parameters: Parameters;
7
+ }
8
+ /** `[Internal]` Creates a deferred computed type. This type is used exclusively in modules to defer resolution of computable types that contain interior references */
9
+ export declare function Computed<Target extends string, Parameters extends TSchema[]>(target: Target, parameters: [...Parameters], options?: SchemaOptions): TComputed<Target, Parameters>;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.Computed = Computed;
5
+ const index_1 = require("../create/index");
6
+ const symbols_1 = require("../symbols/symbols");
7
+ /** `[Internal]` Creates a deferred computed type. This type is used exclusively in modules to defer resolution of computable types that contain interior references */
8
+ function Computed(target, parameters, options) {
9
+ return (0, index_1.CreateType)({ [symbols_1.Kind]: 'Computed', target, parameters }, options);
10
+ }
@@ -0,0 +1 @@
1
+ export * from './computed';
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
16
+ };
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ __exportStar(require("./computed"), exports);
@@ -1,8 +1,9 @@
1
1
  import { Kind, Hint, TransformKind } from '../symbols/index';
2
2
  import { TransformOptions } from '../transform/index';
3
- import { TTemplateLiteral } from '../template-literal/index';
4
- import { TArray } from '../array/index';
5
- import { TBoolean } from '../boolean/index';
3
+ import type { TTemplateLiteral } from '../template-literal/index';
4
+ import type { TArray } from '../array/index';
5
+ import type { TBoolean } from '../boolean/index';
6
+ import type { TComputed } from '../computed/index';
6
7
  import type { TRecord } from '../record/index';
7
8
  import type { TString } from '../string/index';
8
9
  import type { TUnion } from '../union/index';
@@ -15,7 +16,7 @@ import type { TImport } from '../module/index';
15
16
  import type { TInteger } from '../integer/index';
16
17
  import type { TIntersect } from '../intersect/index';
17
18
  import type { TIterator } from '../iterator/index';
18
- import type { TLiteral } from '../literal/index';
19
+ import type { TLiteral, TLiteralValue } from '../literal/index';
19
20
  import type { TMappedKey, TMappedResult } from '../mapped/index';
20
21
  import type { TNever } from '../never/index';
21
22
  import type { TNot } from '../not/index';
@@ -51,6 +52,8 @@ export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator
51
52
  export declare function IsBigInt(value: unknown): value is TBigInt;
52
53
  /** `[Kind-Only]` Returns true if the given value is TBoolean */
53
54
  export declare function IsBoolean(value: unknown): value is TBoolean;
55
+ /** `[Kind-Only]` Returns true if the given value is TComputed */
56
+ export declare function IsComputed(value: unknown): value is TComputed;
54
57
  /** `[Kind-Only]` Returns true if the given value is TConstructor */
55
58
  export declare function IsConstructor(value: unknown): value is TConstructor;
56
59
  /** `[Kind-Only]` Returns true if the given value is TDate */
@@ -77,6 +80,8 @@ export declare function IsLiteralString(value: unknown): value is TLiteral<strin
77
80
  export declare function IsLiteralNumber(value: unknown): value is TLiteral<number>;
78
81
  /** `[Kind-Only]` Returns true if the given value is TLiteral<boolean> */
79
82
  export declare function IsLiteralBoolean(value: unknown): value is TLiteral<boolean>;
83
+ /** `[Kind-Only]` Returns true if the given value is TLiteralValue */
84
+ export declare function IsLiteralValue(value: unknown): value is TLiteralValue;
80
85
  /** `[Kind-Only]` Returns true if the given value is TLiteral */
81
86
  export declare function IsLiteral(value: unknown): value is TLiteral;
82
87
  /** `[Kind-Only]` Returns true if the given value is a TMappedKey */
@@ -8,6 +8,7 @@ exports.IsArray = IsArray;
8
8
  exports.IsAsyncIterator = IsAsyncIterator;
9
9
  exports.IsBigInt = IsBigInt;
10
10
  exports.IsBoolean = IsBoolean;
11
+ exports.IsComputed = IsComputed;
11
12
  exports.IsConstructor = IsConstructor;
12
13
  exports.IsDate = IsDate;
13
14
  exports.IsFunction = IsFunction;
@@ -20,6 +21,7 @@ exports.IsKindOf = IsKindOf;
20
21
  exports.IsLiteralString = IsLiteralString;
21
22
  exports.IsLiteralNumber = IsLiteralNumber;
22
23
  exports.IsLiteralBoolean = IsLiteralBoolean;
24
+ exports.IsLiteralValue = IsLiteralValue;
23
25
  exports.IsLiteral = IsLiteral;
24
26
  exports.IsMappedKey = IsMappedKey;
25
27
  exports.IsMappedResult = IsMappedResult;
@@ -77,6 +79,10 @@ function IsBigInt(value) {
77
79
  function IsBoolean(value) {
78
80
  return IsKindOf(value, 'Boolean');
79
81
  }
82
+ /** `[Kind-Only]` Returns true if the given value is TComputed */
83
+ function IsComputed(value) {
84
+ return IsKindOf(value, 'Computed');
85
+ }
80
86
  /** `[Kind-Only]` Returns true if the given value is TConstructor */
81
87
  function IsConstructor(value) {
82
88
  return IsKindOf(value, 'Constructor');
@@ -125,6 +131,10 @@ function IsLiteralNumber(value) {
125
131
  function IsLiteralBoolean(value) {
126
132
  return IsLiteral(value) && ValueGuard.IsBoolean(value.const);
127
133
  }
134
+ /** `[Kind-Only]` Returns true if the given value is TLiteralValue */
135
+ function IsLiteralValue(value) {
136
+ return ValueGuard.IsBoolean(value) || ValueGuard.IsNumber(value) || ValueGuard.IsString(value);
137
+ }
128
138
  /** `[Kind-Only]` Returns true if the given value is TLiteral */
129
139
  function IsLiteral(value) {
130
140
  return IsKindOf(value, 'Literal');
@@ -1,9 +1,10 @@
1
1
  import { Kind, Hint, TransformKind } from '../symbols/index';
2
2
  import { TypeBoxError } from '../error/index';
3
3
  import { TransformOptions } from '../transform/index';
4
- import { TTemplateLiteral } from '../template-literal/index';
5
- import { TArray } from '../array/index';
6
- import { TBoolean } from '../boolean/index';
4
+ import type { TTemplateLiteral } from '../template-literal/index';
5
+ import type { TArray } from '../array/index';
6
+ import type { TBoolean } from '../boolean/index';
7
+ import type { TComputed } from '../computed/index';
7
8
  import type { TRecord } from '../record/index';
8
9
  import type { TString } from '../string/index';
9
10
  import type { TUnion } from '../union/index';
@@ -54,6 +55,8 @@ export declare function IsAsyncIterator(value: unknown): value is TAsyncIterator
54
55
  export declare function IsBigInt(value: unknown): value is TBigInt;
55
56
  /** Returns true if the given value is TBoolean */
56
57
  export declare function IsBoolean(value: unknown): value is TBoolean;
58
+ /** Returns true if the given value is TComputed */
59
+ export declare function IsComputed(value: unknown): value is TComputed;
57
60
  /** Returns true if the given value is TConstructor */
58
61
  export declare function IsConstructor(value: unknown): value is TConstructor;
59
62
  /** Returns true if the given value is TDate */
@@ -9,6 +9,7 @@ exports.IsArray = IsArray;
9
9
  exports.IsAsyncIterator = IsAsyncIterator;
10
10
  exports.IsBigInt = IsBigInt;
11
11
  exports.IsBoolean = IsBoolean;
12
+ exports.IsComputed = IsComputed;
12
13
  exports.IsConstructor = IsConstructor;
13
14
  exports.IsDate = IsDate;
14
15
  exports.IsFunction = IsFunction;
@@ -62,6 +63,7 @@ const KnownTypes = [
62
63
  'AsyncIterator',
63
64
  'BigInt',
64
65
  'Boolean',
66
+ 'Computed',
65
67
  'Constructor',
66
68
  'Date',
67
69
  'Enum',
@@ -195,6 +197,10 @@ function IsBoolean(value) {
195
197
  value.type === 'boolean' &&
196
198
  IsOptionalString(value.$id));
197
199
  }
200
+ /** Returns true if the given value is TComputed */
201
+ function IsComputed(value) {
202
+ return IsKindOf(value, 'Computed') && IsString(value.target) && ValueGuard.IsArray(value.parameters) && value.parameters.every((schema) => IsSchema(schema));
203
+ }
198
204
  /** Returns true if the given value is TConstructor */
199
205
  function IsConstructor(value) {
200
206
  // prettier-ignore
@@ -3,11 +3,11 @@ import type { Ensure, Evaluate } from '../helpers/index';
3
3
  import type { TProperties } from '../object/index';
4
4
  import { type TIndex } from './indexed';
5
5
  import { type TMappedResult, type TMappedKey } from '../mapped/index';
6
- type TMappedIndexPropertyKey<T extends TSchema, K extends PropertyKey> = {
7
- [_ in K]: TIndex<T, [K]>;
6
+ type TMappedIndexPropertyKey<Type extends TSchema, Key extends PropertyKey> = {
7
+ [_ in Key]: TIndex<Type, [Key]>;
8
8
  };
9
- type TMappedIndexPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TProperties = {}> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TMappedIndexPropertyKeys<T, R, Acc & TMappedIndexPropertyKey<T, L>> : Acc);
10
- type TMappedIndexProperties<T extends TSchema, K extends TMappedKey> = Evaluate<TMappedIndexPropertyKeys<T, K['keys']>>;
11
- export type TIndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>> = (Ensure<TMappedResult<P>>);
12
- export declare function IndexFromMappedKey<T extends TSchema, K extends TMappedKey, P extends TProperties = TMappedIndexProperties<T, K>>(T: T, K: K, options?: SchemaOptions): TMappedResult<P>;
9
+ type TMappedIndexPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TProperties = {}> = (PropertyKeys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? TMappedIndexPropertyKeys<Type, Right, Result & TMappedIndexPropertyKey<Type, Left>> : Result);
10
+ type TMappedIndexProperties<Type extends TSchema, MappedKey extends TMappedKey> = Evaluate<TMappedIndexPropertyKeys<Type, MappedKey['keys']>>;
11
+ export type TIndexFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TMappedIndexProperties<Type, MappedKey>> = (Ensure<TMappedResult<Properties>>);
12
+ export declare function IndexFromMappedKey<Type extends TSchema, MappedKey extends TMappedKey, Properties extends TProperties = TMappedIndexProperties<Type, MappedKey>>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TMappedResult<Properties>;
13
13
  export {};
@@ -6,21 +6,21 @@ const indexed_1 = require("./indexed");
6
6
  const index_1 = require("../mapped/index");
7
7
  const value_1 = require("../clone/value");
8
8
  // prettier-ignore
9
- function MappedIndexPropertyKey(T, K, options) {
10
- return { [K]: (0, indexed_1.Index)(T, [K], (0, value_1.Clone)(options)) };
9
+ function MappedIndexPropertyKey(type, key, options) {
10
+ return { [key]: (0, indexed_1.Index)(type, [key], (0, value_1.Clone)(options)) };
11
11
  }
12
12
  // prettier-ignore
13
- function MappedIndexPropertyKeys(T, K, options) {
14
- return K.reduce((Acc, L) => {
15
- return { ...Acc, ...MappedIndexPropertyKey(T, L, options) };
13
+ function MappedIndexPropertyKeys(type, propertyKeys, options) {
14
+ return propertyKeys.reduce((result, left) => {
15
+ return { ...result, ...MappedIndexPropertyKey(type, left, options) };
16
16
  }, {});
17
17
  }
18
18
  // prettier-ignore
19
- function MappedIndexProperties(T, K, options) {
20
- return MappedIndexPropertyKeys(T, K.keys, options);
19
+ function MappedIndexProperties(type, mappedKey, options) {
20
+ return MappedIndexPropertyKeys(type, mappedKey.keys, options);
21
21
  }
22
22
  // prettier-ignore
23
- function IndexFromMappedKey(T, K, options) {
24
- const P = MappedIndexProperties(T, K, options);
25
- return (0, index_1.MappedResult)(P);
23
+ function IndexFromMappedKey(type, mappedKey, options) {
24
+ const properties = MappedIndexProperties(type, mappedKey, options);
25
+ return (0, index_1.MappedResult)(properties);
26
26
  }
@@ -3,10 +3,10 @@ import type { TProperties } from '../object/index';
3
3
  import { type TMappedResult } from '../mapped/index';
4
4
  import { type TIndexPropertyKeys } from './indexed-property-keys';
5
5
  import { type TIndex } from './index';
6
- type TFromProperties<T extends TSchema, P extends TProperties> = ({
7
- [K2 in keyof P]: TIndex<T, TIndexPropertyKeys<P[K2]>>;
6
+ type TFromProperties<Type extends TSchema, Properties extends TProperties> = ({
7
+ [K2 in keyof Properties]: TIndex<Type, TIndexPropertyKeys<Properties[K2]>>;
8
8
  });
9
- type TFromMappedResult<T extends TSchema, R extends TMappedResult> = (TFromProperties<T, R['properties']>);
10
- export type TIndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>> = (TMappedResult<P>);
11
- export declare function IndexFromMappedResult<T extends TSchema, R extends TMappedResult, P extends TProperties = TFromMappedResult<T, R>>(T: T, R: R, options?: SchemaOptions): TMappedResult<P>;
9
+ type TFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult> = (TFromProperties<Type, MappedResult['properties']>);
10
+ export type TIndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<Type, MappedResult>> = (TMappedResult<Properties>);
11
+ export declare function IndexFromMappedResult<Type extends TSchema, MappedResult extends TMappedResult, Properties extends TProperties = TFromMappedResult<Type, MappedResult>>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TMappedResult<Properties>;
12
12
  export {};
@@ -6,19 +6,20 @@ const index_1 = require("../mapped/index");
6
6
  const indexed_property_keys_1 = require("./indexed-property-keys");
7
7
  const index_2 = require("./index");
8
8
  // prettier-ignore
9
- function FromProperties(T, P, options) {
10
- const Acc = {};
11
- for (const K2 of Object.getOwnPropertyNames(P)) {
12
- Acc[K2] = (0, index_2.Index)(T, (0, indexed_property_keys_1.IndexPropertyKeys)(P[K2]), options);
9
+ function FromProperties(type, properties, options) {
10
+ const result = {};
11
+ for (const K2 of Object.getOwnPropertyNames(properties)) {
12
+ const keys = (0, indexed_property_keys_1.IndexPropertyKeys)(properties[K2]);
13
+ result[K2] = (0, index_2.Index)(type, keys, options);
13
14
  }
14
- return Acc;
15
+ return result;
15
16
  }
16
17
  // prettier-ignore
17
- function FromMappedResult(T, R, options) {
18
- return FromProperties(T, R.properties, options);
18
+ function FromMappedResult(type, mappedResult, options) {
19
+ return FromProperties(type, mappedResult.properties, options);
19
20
  }
20
21
  // prettier-ignore
21
- function IndexFromMappedResult(T, R, options) {
22
- const P = FromMappedResult(T, R, options);
23
- return (0, index_1.MappedResult)(P);
22
+ function IndexFromMappedResult(type, mappedResult, options) {
23
+ const properties = FromMappedResult(type, mappedResult, options);
24
+ return (0, index_1.MappedResult)(properties);
24
25
  }
@@ -4,11 +4,11 @@ import type { TInteger } from '../integer/index';
4
4
  import type { TNumber } from '../number/index';
5
5
  import type { TSchema } from '../schema/index';
6
6
  import type { TUnion } from '../union/index';
7
- type TFromTemplateLiteral<T extends TTemplateLiteral, R extends string[] = TTemplateLiteralGenerate<T>> = (R);
8
- type TFromUnion<T extends TSchema[], Acc extends string[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromUnion<R, [...Acc, ...TIndexPropertyKeys<L>]> : Acc);
9
- type TFromLiteral<T extends TLiteralValue> = (T extends PropertyKey ? [`${T}`] : []);
10
- export type TIndexPropertyKeys<T extends TSchema> = (T extends TTemplateLiteral ? TFromTemplateLiteral<T> : T extends TUnion<infer S> ? TFromUnion<S> : T extends TLiteral<infer S> ? TFromLiteral<S> : T extends TNumber ? ['[number]'] : T extends TInteger ? ['[number]'] : [
11
- ]);
7
+ type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral, Result extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = Result;
8
+ type TFromUnion<Types extends TSchema[], Result extends string[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromUnion<Right, [...Result, ...TIndexPropertyKeys<Left>]> : Result);
9
+ type TFromLiteral<LiteralValue extends TLiteralValue> = (LiteralValue extends PropertyKey ? [`${LiteralValue}`] : []);
10
+ export type TIndexPropertyKeys<Type extends TSchema, Result extends PropertyKey[] = (Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TLiteral<infer LiteralValue extends TLiteralValue> ? TFromLiteral<LiteralValue> : Type extends TNumber ? ['[number]'] : Type extends TInteger ? ['[number]'] : [
11
+ ])> = Result;
12
12
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
13
- export declare function IndexPropertyKeys<T extends TSchema>(T: T): TIndexPropertyKeys<T>;
13
+ export declare function IndexPropertyKeys<Type extends TSchema>(type: Type): TIndexPropertyKeys<Type>;
14
14
  export {};
@@ -8,16 +8,16 @@ const index_1 = require("../template-literal/index");
8
8
  // ------------------------------------------------------------------
9
9
  const kind_1 = require("../guard/kind");
10
10
  // prettier-ignore
11
- function FromTemplateLiteral(T) {
12
- const R = (0, index_1.TemplateLiteralGenerate)(T);
13
- return R.map(S => S.toString());
11
+ function FromTemplateLiteral(templateLiteral) {
12
+ const result = (0, index_1.TemplateLiteralGenerate)(templateLiteral);
13
+ return result.map(S => S.toString());
14
14
  }
15
15
  // prettier-ignore
16
- function FromUnion(T) {
17
- const Acc = [];
18
- for (const L of T)
19
- Acc.push(...IndexPropertyKeys(L));
20
- return Acc;
16
+ function FromUnion(type) {
17
+ const result = [];
18
+ for (const left of type)
19
+ result.push(...IndexPropertyKeys(left));
20
+ return result;
21
21
  }
22
22
  // prettier-ignore
23
23
  function FromLiteral(T) {
@@ -26,11 +26,11 @@ function FromLiteral(T) {
26
26
  }
27
27
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
28
28
  // prettier-ignore
29
- function IndexPropertyKeys(T) {
30
- return [...new Set(((0, kind_1.IsTemplateLiteral)(T) ? FromTemplateLiteral(T) :
31
- (0, kind_1.IsUnion)(T) ? FromUnion(T.anyOf) :
32
- (0, kind_1.IsLiteral)(T) ? FromLiteral(T.const) :
33
- (0, kind_1.IsNumber)(T) ? ['[number]'] :
34
- (0, kind_1.IsInteger)(T) ? ['[number]'] :
29
+ function IndexPropertyKeys(type) {
30
+ return [...new Set(((0, kind_1.IsTemplateLiteral)(type) ? FromTemplateLiteral(type) :
31
+ (0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf) :
32
+ (0, kind_1.IsLiteral)(type) ? FromLiteral(type.const) :
33
+ (0, kind_1.IsNumber)(type) ? ['[number]'] :
34
+ (0, kind_1.IsInteger)(type) ? ['[number]'] :
35
35
  []))];
36
36
  }
@@ -1,4 +1,6 @@
1
1
  import { type TSchema, SchemaOptions } from '../schema/index';
2
+ import { type TComputed } from '../computed/index';
3
+ import { type TLiteral, type TLiteralValue } from '../literal/index';
2
4
  import { type TObject, type TProperties } from '../object/index';
3
5
  import { type Assert } from '../helpers/index';
4
6
  import { type TNever } from '../never/index';
@@ -8,33 +10,45 @@ import { TMappedResult, type TMappedKey } from '../mapped/index';
8
10
  import { type TUnion } from '../union/index';
9
11
  import { type TTuple } from '../tuple/index';
10
12
  import { type TArray } from '../array/index';
13
+ import { type TRef } from '../ref/index';
11
14
  import { type TIntersectEvaluated } from '../intersect/index';
12
15
  import { type TUnionEvaluated } from '../union/index';
13
16
  import { type TIndexPropertyKeys } from './indexed-property-keys';
14
17
  import { type TIndexFromMappedKey } from './indexed-from-mapped-key';
15
18
  import { type TIndexFromMappedResult } from './indexed-from-mapped-result';
16
- type TFromRest<T extends TSchema[], K extends PropertyKey, Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Acc, Assert<TIndexFromPropertyKey<L, K>, TSchema>]> : Acc);
17
- type TFromIntersectRest<T extends TSchema[], Acc extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? TFromIntersectRest<R, [...Acc]> : TFromIntersectRest<R, [...Acc, L]> : Acc);
18
- type TFromIntersect<T extends TSchema[], K extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<T, K>>>);
19
- type TFromUnionRest<T extends TSchema[], Acc extends TSchema[] = []> = T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? L extends TNever ? [] : TFromUnionRest<R, [L, ...Acc]> : Acc;
20
- type TFromUnion<T extends TSchema[], K extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<T, K>>>);
21
- type TFromTuple<T extends TSchema[], K extends PropertyKey> = (K extends keyof T ? T[K] : K extends '[number]' ? TUnionEvaluated<T> : TNever);
22
- type TFromArray<T extends TSchema, K extends PropertyKey> = (K extends '[number]' ? T : TNever);
23
- type AssertPropertyKey<T> = Assert<T, string | number>;
24
- type TFromProperty<T extends TProperties, K extends PropertyKey> = (K extends keyof T ? T[K] : `${AssertPropertyKey<K>}` extends `${AssertPropertyKey<keyof T>}` ? T[AssertPropertyKey<K>] : TNever);
25
- export type TIndexFromPropertyKey<T extends TSchema, K extends PropertyKey> = (T extends TRecursive<infer S> ? TIndexFromPropertyKey<S, K> : T extends TIntersect<infer S> ? TFromIntersect<S, K> : T extends TUnion<infer S> ? TFromUnion<S, K> : T extends TTuple<infer S> ? TFromTuple<S, K> : T extends TArray<infer S> ? TFromArray<S, K> : T extends TObject<infer S> ? TFromProperty<S, K> : TNever);
26
- export declare function IndexFromPropertyKey<T extends TSchema, K extends PropertyKey>(T: T, K: K): TIndexFromPropertyKey<T, K>;
27
- export type TIndexFromPropertyKeys<T extends TSchema, K extends PropertyKey[], Acc extends TSchema[] = []> = (K extends [infer L extends PropertyKey, ...infer R extends PropertyKey[]] ? TIndexFromPropertyKeys<T, R, [...Acc, Assert<TIndexFromPropertyKey<T, L>, TSchema>]> : Acc);
28
- export declare function IndexFromPropertyKeys<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): TIndexFromPropertyKeys<T, K>;
29
- type FromSchema<T extends TSchema, K extends PropertyKey[]> = (TUnionEvaluated<TIndexFromPropertyKeys<T, K>>);
30
- declare function FromSchema<T extends TSchema, K extends PropertyKey[]>(T: T, K: [...K]): FromSchema<T, K>;
31
- export type TIndex<T extends TSchema, K extends PropertyKey[]> = (FromSchema<T, K>);
19
+ type TFromRest<T extends TSchema[], K extends PropertyKey, Result extends TSchema[] = []> = (T extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TFromRest<R, K, [...Result, Assert<TIndexFromPropertyKey<L, K>, TSchema>]> : Result);
20
+ type TFromIntersectRest<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? TFromIntersectRest<Right, [...Result]> : TFromIntersectRest<Right, [...Result, Left]> : Result);
21
+ type TFromIntersect<Types extends TSchema[], Key extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<Types, Key>>>);
22
+ type TFromUnionRest<Types extends TSchema[], Result extends TSchema[] = []> = Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TNever ? [] : TFromUnionRest<Right, [Left, ...Result]> : Result;
23
+ type TFromUnion<Types extends TSchema[], Key extends PropertyKey> = (TUnionEvaluated<TFromUnionRest<TFromRest<Types, Key>>>);
24
+ type TFromTuple<Types extends TSchema[], Key extends PropertyKey, Result extends TSchema = (Key extends '[number]' ? TUnionEvaluated<Types> : Key extends keyof Types ? Types[Key] extends infer Type extends TSchema ? Type : TNever : TNever)> = Result;
25
+ type TFromArray<Type extends TSchema, Key extends PropertyKey> = (Key extends '[number]' ? Type : TNever);
26
+ type AssertPropertyKey<T extends unknown> = Assert<T, string | number>;
27
+ type TFromProperty<Properties extends TProperties, Key extends PropertyKey, Result extends TSchema = (Key extends keyof Properties ? Properties[Key] : `${AssertPropertyKey<Key>}` extends `${AssertPropertyKey<keyof Properties>}` ? Properties[AssertPropertyKey<Key>] : TNever)> = Result;
28
+ export type TIndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = (Type extends TRecursive<infer S extends TSchema> ? TIndexFromPropertyKey<S, Key> : Type extends TIntersect<infer S extends TSchema[]> ? TFromIntersect<S, Key> : Type extends TUnion<infer S extends TSchema[]> ? TFromUnion<S, Key> : Type extends TTuple<infer S extends TSchema[]> ? TFromTuple<S, Key> : Type extends TArray<infer S extends TSchema> ? TFromArray<S, Key> : Type extends TObject<infer S extends TProperties> ? TFromProperty<S, Key> : TNever);
29
+ export declare function IndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey>(type: Type, key: Key): TIndexFromPropertyKey<Type, Key>;
30
+ export type TIndexFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TSchema[] = []> = (PropertyKeys extends [infer Left extends PropertyKey, ...infer Right extends PropertyKey[]] ? TIndexFromPropertyKeys<Type, Right, [...Result, Assert<TIndexFromPropertyKey<Type, Left>, TSchema>]> : Result);
31
+ export declare function IndexFromPropertyKeys<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: [...PropertyKeys]): TIndexFromPropertyKeys<Type, PropertyKeys>;
32
+ type TFromType<Type extends TSchema, PropertyKeys extends PropertyKey[], Result extends TSchema[] = TIndexFromPropertyKeys<Type, PropertyKeys>> = TUnionEvaluated<Result>;
33
+ 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]> : TUnionEvaluated<Result>);
34
+ type TResolvePropertyKeys<Key extends TSchema | PropertyKey[]> = Key extends TSchema ? TIndexPropertyKeys<Key> : Key;
35
+ type TResolveTypeKey<Key extends TSchema | PropertyKey[]> = Key extends PropertyKey[] ? TUnionFromPropertyKeys<Key> : Key;
36
+ export type TIndex<Type extends TSchema, Key extends TSchema | PropertyKey[], IsTypeRef extends boolean = Type extends TRef ? true : false, IsKeyRef extends boolean = Key extends TRef ? true : false> = (Key extends TMappedResult ? TIndexFromMappedResult<Type, Key> : Key extends TMappedKey ? TIndexFromMappedKey<Type, Key> : [
37
+ IsTypeRef,
38
+ IsKeyRef
39
+ ] extends [true, true] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : [
40
+ IsTypeRef,
41
+ IsKeyRef
42
+ ] extends [false, true] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : [
43
+ IsTypeRef,
44
+ IsKeyRef
45
+ ] extends [true, false] ? TComputed<'Index', [Type, TResolveTypeKey<Key>]> : TFromType<Type, TResolvePropertyKeys<Key>>);
32
46
  /** `[Json]` Returns an Indexed property type for the given keys */
33
- export declare function Index<T extends TSchema, K extends TMappedResult>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedResult<T, K>;
47
+ export declare function Index<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TIndex<Type, Key>;
34
48
  /** `[Json]` Returns an Indexed property type for the given keys */
35
- export declare function Index<T extends TSchema, K extends TMappedKey>(T: T, K: K, options?: SchemaOptions): TIndexFromMappedKey<T, K>;
49
+ export declare function Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
36
50
  /** `[Json]` Returns an Indexed property type for the given keys */
37
- export declare function Index<T extends TSchema, K extends TSchema, I extends PropertyKey[] = TIndexPropertyKeys<K>>(T: T, K: K, options?: SchemaOptions): TIndex<T, I>;
51
+ export declare function Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
38
52
  /** `[Json]` Returns an Indexed property type for the given keys */
39
- export declare function Index<T extends TSchema, K extends PropertyKey[]>(T: T, K: readonly [...K], options?: SchemaOptions): TIndex<T, K>;
53
+ export declare function Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
40
54
  export {};