@sinclair/typebox 0.34.9 → 0.34.11

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.
@@ -13,10 +13,11 @@ const index_8 = require("../type/registry/index");
13
13
  const index_9 = require("../type/keyof/index");
14
14
  const extends_undefined_1 = require("../type/extends/extends-undefined");
15
15
  const index_10 = require("../type/never/index");
16
+ const index_11 = require("../type/ref/index");
16
17
  // ------------------------------------------------------------------
17
18
  // ValueGuard
18
19
  // ------------------------------------------------------------------
19
- const index_11 = require("../value/guard/index");
20
+ const index_12 = require("../value/guard/index");
20
21
  // ------------------------------------------------------------------
21
22
  // TypeGuard
22
23
  // ------------------------------------------------------------------
@@ -211,17 +212,17 @@ var TypeCompiler;
211
212
  function* FromArray(schema, references, value) {
212
213
  yield `Array.isArray(${value})`;
213
214
  const [parameter, accumulator] = [CreateParameter('value', 'any'), CreateParameter('acc', 'number')];
214
- if ((0, index_11.IsNumber)(schema.maxItems))
215
+ if ((0, index_12.IsNumber)(schema.maxItems))
215
216
  yield `${value}.length <= ${schema.maxItems}`;
216
- if ((0, index_11.IsNumber)(schema.minItems))
217
+ if ((0, index_12.IsNumber)(schema.minItems))
217
218
  yield `${value}.length >= ${schema.minItems}`;
218
219
  const elementExpression = CreateExpression(schema.items, references, 'value');
219
220
  yield `${value}.every((${parameter}) => ${elementExpression})`;
220
- if ((0, type_1.IsSchema)(schema.contains) || (0, index_11.IsNumber)(schema.minContains) || (0, index_11.IsNumber)(schema.maxContains)) {
221
+ if ((0, type_1.IsSchema)(schema.contains) || (0, index_12.IsNumber)(schema.minContains) || (0, index_12.IsNumber)(schema.maxContains)) {
221
222
  const containsSchema = (0, type_1.IsSchema)(schema.contains) ? schema.contains : (0, index_10.Never)();
222
223
  const checkExpression = CreateExpression(containsSchema, references, 'value');
223
- const checkMinContains = (0, index_11.IsNumber)(schema.minContains) ? [`(count >= ${schema.minContains})`] : [];
224
- const checkMaxContains = (0, index_11.IsNumber)(schema.maxContains) ? [`(count <= ${schema.maxContains})`] : [];
224
+ const checkMinContains = (0, index_12.IsNumber)(schema.minContains) ? [`(count >= ${schema.minContains})`] : [];
225
+ const checkMaxContains = (0, index_12.IsNumber)(schema.maxContains) ? [`(count <= ${schema.maxContains})`] : [];
225
226
  const checkCount = `const count = value.reduce((${accumulator}, ${parameter}) => ${checkExpression} ? acc + 1 : acc, 0)`;
226
227
  const check = [`(count > 0)`, ...checkMinContains, ...checkMaxContains].join(' && ');
227
228
  yield `((${parameter}) => { ${checkCount}; return ${check}})(${value})`;
@@ -237,15 +238,15 @@ var TypeCompiler;
237
238
  }
238
239
  function* FromBigInt(schema, references, value) {
239
240
  yield `(typeof ${value} === 'bigint')`;
240
- if ((0, index_11.IsBigInt)(schema.exclusiveMaximum))
241
+ if ((0, index_12.IsBigInt)(schema.exclusiveMaximum))
241
242
  yield `${value} < BigInt(${schema.exclusiveMaximum})`;
242
- if ((0, index_11.IsBigInt)(schema.exclusiveMinimum))
243
+ if ((0, index_12.IsBigInt)(schema.exclusiveMinimum))
243
244
  yield `${value} > BigInt(${schema.exclusiveMinimum})`;
244
- if ((0, index_11.IsBigInt)(schema.maximum))
245
+ if ((0, index_12.IsBigInt)(schema.maximum))
245
246
  yield `${value} <= BigInt(${schema.maximum})`;
246
- if ((0, index_11.IsBigInt)(schema.minimum))
247
+ if ((0, index_12.IsBigInt)(schema.minimum))
247
248
  yield `${value} >= BigInt(${schema.minimum})`;
248
- if ((0, index_11.IsBigInt)(schema.multipleOf))
249
+ if ((0, index_12.IsBigInt)(schema.multipleOf))
249
250
  yield `(${value} % BigInt(${schema.multipleOf})) === 0`;
250
251
  }
251
252
  function* FromBoolean(schema, references, value) {
@@ -256,36 +257,37 @@ var TypeCompiler;
256
257
  }
257
258
  function* FromDate(schema, references, value) {
258
259
  yield `(${value} instanceof Date) && Number.isFinite(${value}.getTime())`;
259
- if ((0, index_11.IsNumber)(schema.exclusiveMaximumTimestamp))
260
+ if ((0, index_12.IsNumber)(schema.exclusiveMaximumTimestamp))
260
261
  yield `${value}.getTime() < ${schema.exclusiveMaximumTimestamp}`;
261
- if ((0, index_11.IsNumber)(schema.exclusiveMinimumTimestamp))
262
+ if ((0, index_12.IsNumber)(schema.exclusiveMinimumTimestamp))
262
263
  yield `${value}.getTime() > ${schema.exclusiveMinimumTimestamp}`;
263
- if ((0, index_11.IsNumber)(schema.maximumTimestamp))
264
+ if ((0, index_12.IsNumber)(schema.maximumTimestamp))
264
265
  yield `${value}.getTime() <= ${schema.maximumTimestamp}`;
265
- if ((0, index_11.IsNumber)(schema.minimumTimestamp))
266
+ if ((0, index_12.IsNumber)(schema.minimumTimestamp))
266
267
  yield `${value}.getTime() >= ${schema.minimumTimestamp}`;
267
- if ((0, index_11.IsNumber)(schema.multipleOfTimestamp))
268
+ if ((0, index_12.IsNumber)(schema.multipleOfTimestamp))
268
269
  yield `(${value}.getTime() % ${schema.multipleOfTimestamp}) === 0`;
269
270
  }
270
271
  function* FromFunction(schema, references, value) {
271
272
  yield `(typeof ${value} === 'function')`;
272
273
  }
273
274
  function* FromImport(schema, references, value) {
274
- const definitions = globalThis.Object.values(schema.$defs);
275
- const target = schema.$defs[schema.$ref];
276
- yield* Visit(target, [...references, ...definitions], value);
275
+ const members = globalThis.Object.getOwnPropertyNames(schema.$defs).reduce((result, key) => {
276
+ return [...result, schema.$defs[key]];
277
+ }, []);
278
+ yield* Visit((0, index_11.Ref)(schema.$ref), [...references, ...members], value);
277
279
  }
278
280
  function* FromInteger(schema, references, value) {
279
281
  yield `Number.isInteger(${value})`;
280
- if ((0, index_11.IsNumber)(schema.exclusiveMaximum))
282
+ if ((0, index_12.IsNumber)(schema.exclusiveMaximum))
281
283
  yield `${value} < ${schema.exclusiveMaximum}`;
282
- if ((0, index_11.IsNumber)(schema.exclusiveMinimum))
284
+ if ((0, index_12.IsNumber)(schema.exclusiveMinimum))
283
285
  yield `${value} > ${schema.exclusiveMinimum}`;
284
- if ((0, index_11.IsNumber)(schema.maximum))
286
+ if ((0, index_12.IsNumber)(schema.maximum))
285
287
  yield `${value} <= ${schema.maximum}`;
286
- if ((0, index_11.IsNumber)(schema.minimum))
288
+ if ((0, index_12.IsNumber)(schema.minimum))
287
289
  yield `${value} >= ${schema.minimum}`;
288
- if ((0, index_11.IsNumber)(schema.multipleOf))
290
+ if ((0, index_12.IsNumber)(schema.multipleOf))
289
291
  yield `(${value} % ${schema.multipleOf}) === 0`;
290
292
  }
291
293
  function* FromIntersect(schema, references, value) {
@@ -327,22 +329,22 @@ var TypeCompiler;
327
329
  }
328
330
  function* FromNumber(schema, references, value) {
329
331
  yield Policy.IsNumberLike(value);
330
- if ((0, index_11.IsNumber)(schema.exclusiveMaximum))
332
+ if ((0, index_12.IsNumber)(schema.exclusiveMaximum))
331
333
  yield `${value} < ${schema.exclusiveMaximum}`;
332
- if ((0, index_11.IsNumber)(schema.exclusiveMinimum))
334
+ if ((0, index_12.IsNumber)(schema.exclusiveMinimum))
333
335
  yield `${value} > ${schema.exclusiveMinimum}`;
334
- if ((0, index_11.IsNumber)(schema.maximum))
336
+ if ((0, index_12.IsNumber)(schema.maximum))
335
337
  yield `${value} <= ${schema.maximum}`;
336
- if ((0, index_11.IsNumber)(schema.minimum))
338
+ if ((0, index_12.IsNumber)(schema.minimum))
337
339
  yield `${value} >= ${schema.minimum}`;
338
- if ((0, index_11.IsNumber)(schema.multipleOf))
340
+ if ((0, index_12.IsNumber)(schema.multipleOf))
339
341
  yield `(${value} % ${schema.multipleOf}) === 0`;
340
342
  }
341
343
  function* FromObject(schema, references, value) {
342
344
  yield Policy.IsObjectLike(value);
343
- if ((0, index_11.IsNumber)(schema.minProperties))
345
+ if ((0, index_12.IsNumber)(schema.minProperties))
344
346
  yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
345
- if ((0, index_11.IsNumber)(schema.maxProperties))
347
+ if ((0, index_12.IsNumber)(schema.maxProperties))
346
348
  yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}`;
347
349
  const knownKeys = Object.getOwnPropertyNames(schema.properties);
348
350
  for (const knownKey of knownKeys) {
@@ -378,9 +380,9 @@ var TypeCompiler;
378
380
  }
379
381
  function* FromRecord(schema, references, value) {
380
382
  yield Policy.IsRecordLike(value);
381
- if ((0, index_11.IsNumber)(schema.minProperties))
383
+ if ((0, index_12.IsNumber)(schema.minProperties))
382
384
  yield `Object.getOwnPropertyNames(${value}).length >= ${schema.minProperties}`;
383
- if ((0, index_11.IsNumber)(schema.maxProperties))
385
+ if ((0, index_12.IsNumber)(schema.maxProperties))
384
386
  yield `Object.getOwnPropertyNames(${value}).length <= ${schema.maxProperties}`;
385
387
  const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
386
388
  const variable = CreateVariable(`${new RegExp(patternKey)}`);
@@ -392,29 +394,25 @@ var TypeCompiler;
392
394
  function* FromRef(schema, references, value) {
393
395
  const target = (0, index_5.Deref)(schema, references);
394
396
  // Reference: If we have seen this reference before we can just yield and return the function call.
395
- // If this isn't the case we defer to visit to generate and set the _recursion_end_for_ for subsequent
396
- // passes. This operation is very awkward as we are using the functions state to store values to
397
- // enable self referential types to terminate. This needs to be refactored.
398
- const recursiveEnd = `_recursion_end_for_${schema.$ref}`;
399
- if (state.functions.has(recursiveEnd))
397
+ // If this isn't the case we defer to visit to generate and set the function for subsequent passes.
398
+ if (state.functions.has(schema.$ref))
400
399
  return yield `${CreateFunctionName(schema.$ref)}(${value})`;
401
- state.functions.set(recursiveEnd, ''); // terminate recursion here by setting the name.
402
400
  yield* Visit(target, references, value);
403
401
  }
404
402
  function* FromRegExp(schema, references, value) {
405
403
  const variable = CreateVariable(`${new RegExp(schema.source, schema.flags)};`);
406
404
  yield `(typeof ${value} === 'string')`;
407
- if ((0, index_11.IsNumber)(schema.maxLength))
405
+ if ((0, index_12.IsNumber)(schema.maxLength))
408
406
  yield `${value}.length <= ${schema.maxLength}`;
409
- if ((0, index_11.IsNumber)(schema.minLength))
407
+ if ((0, index_12.IsNumber)(schema.minLength))
410
408
  yield `${value}.length >= ${schema.minLength}`;
411
409
  yield `${variable}.test(${value})`;
412
410
  }
413
411
  function* FromString(schema, references, value) {
414
412
  yield `(typeof ${value} === 'string')`;
415
- if ((0, index_11.IsNumber)(schema.maxLength))
413
+ if ((0, index_12.IsNumber)(schema.maxLength))
416
414
  yield `${value}.length <= ${schema.maxLength}`;
417
- if ((0, index_11.IsNumber)(schema.minLength))
415
+ if ((0, index_12.IsNumber)(schema.minLength))
418
416
  yield `${value}.length >= ${schema.minLength}`;
419
417
  if (schema.pattern !== undefined) {
420
418
  const variable = CreateVariable(`${new RegExp(schema.pattern)};`);
@@ -455,9 +453,9 @@ var TypeCompiler;
455
453
  }
456
454
  function* FromUint8Array(schema, references, value) {
457
455
  yield `${value} instanceof Uint8Array`;
458
- if ((0, index_11.IsNumber)(schema.maxByteLength))
456
+ if ((0, index_12.IsNumber)(schema.maxByteLength))
459
457
  yield `(${value}.length <= ${schema.maxByteLength})`;
460
- if ((0, index_11.IsNumber)(schema.minByteLength))
458
+ if ((0, index_12.IsNumber)(schema.minByteLength))
461
459
  yield `(${value}.length >= ${schema.minByteLength})`;
462
460
  }
463
461
  function* FromUnknown(schema, references, value) {
@@ -472,17 +470,21 @@ var TypeCompiler;
472
470
  yield `kind('${schema[index_7.Kind]}', ${instance}, ${value})`;
473
471
  }
474
472
  function* Visit(schema, references, value, useHoisting = true) {
475
- const references_ = (0, index_11.IsString)(schema.$id) ? [...references, schema] : references;
473
+ const references_ = (0, index_12.IsString)(schema.$id) ? [...references, schema] : references;
476
474
  const schema_ = schema;
477
475
  // --------------------------------------------------------------
478
476
  // Hoisting
479
477
  // --------------------------------------------------------------
480
- if (useHoisting && (0, index_11.IsString)(schema.$id)) {
478
+ if (useHoisting && (0, index_12.IsString)(schema.$id)) {
481
479
  const functionName = CreateFunctionName(schema.$id);
482
480
  if (state.functions.has(functionName)) {
483
481
  return yield `${functionName}(${value})`;
484
482
  }
485
483
  else {
484
+ // Note: In the case of cyclic types, we need to create a 'functions' record
485
+ // to prevent infinitely re-visiting the CreateFunction. Subsequent attempts
486
+ // to visit will be caught by the above condition.
487
+ state.functions.set(functionName, '<deferred>');
486
488
  const functionCode = CreateFunction(functionName, schema, references, 'value', false);
487
489
  state.functions.set(functionName, functionCode);
488
490
  return yield `${functionName}(${value})`;
@@ -607,7 +609,7 @@ var TypeCompiler;
607
609
  const functions = [...state.functions.values()];
608
610
  const variables = [...state.variables.values()];
609
611
  // prettier-ignore
610
- const checkFunction = (0, index_11.IsString)(schema.$id) // ensure top level schemas with $id's are hoisted
612
+ const checkFunction = (0, index_12.IsString)(schema.$id) // ensure top level schemas with $id's are hoisted
611
613
  ? `return function check(${parameter})${returns} {\n return ${CreateFunctionName(schema.$id)}(value)\n}`
612
614
  : `return ${functionCode}`;
613
615
  return [...variables, ...functions, checkFunction].join('\n');
@@ -616,8 +618,8 @@ var TypeCompiler;
616
618
  function Code(...args) {
617
619
  const defaults = { language: 'javascript' };
618
620
  // prettier-ignore
619
- const [schema, references, options] = (args.length === 2 && (0, index_11.IsArray)(args[1]) ? [args[0], args[1], defaults] :
620
- args.length === 2 && !(0, index_11.IsArray)(args[1]) ? [args[0], [], args[1]] :
621
+ const [schema, references, options] = (args.length === 2 && (0, index_12.IsArray)(args[1]) ? [args[0], args[1], defaults] :
622
+ args.length === 2 && !(0, index_12.IsArray)(args[1]) ? [args[0], [], args[1]] :
621
623
  args.length === 3 ? [args[0], args[1], args[2]] :
622
624
  args.length === 1 ? [args[0], [], defaults] :
623
625
  [null, [], defaults]);
@@ -48,7 +48,7 @@ export declare const Module: Runtime.Module<{
48
48
  Iterator: Runtime.ITuple<Types.TIterator<Types.TSchema>>;
49
49
  Awaited: Runtime.ITuple<Types.TSchema>;
50
50
  Array: Runtime.ITuple<Types.TArray<Types.TSchema>>;
51
- Record: Runtime.ITuple<Types.TSchema>;
51
+ Record: Runtime.ITuple<Types.TNever>;
52
52
  Promise: Runtime.ITuple<Types.TPromise<Types.TSchema>>;
53
53
  ConstructorParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
54
54
  FunctionParameters: Runtime.ITuple<Types.TTuple<Types.TSchema[]>>;
@@ -9,8 +9,7 @@ const index_2 = require("./index");
9
9
  function FromProperties(type, properties, options) {
10
10
  const result = {};
11
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);
12
+ result[K2] = (0, index_2.Index)(type, (0, indexed_property_keys_1.IndexPropertyKeys)(properties[K2]), options);
14
13
  }
15
14
  return result;
16
15
  }
@@ -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<TemplateLiteral extends TTemplateLiteral, Result extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = Result;
7
+ type TFromTemplateLiteral<TemplateLiteral extends TTemplateLiteral, Keys extends string[] = TTemplateLiteralGenerate<TemplateLiteral>> = (Keys);
8
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
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;
10
+ export type TIndexPropertyKeys<Type extends TSchema> = (Type extends TTemplateLiteral ? TFromTemplateLiteral<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types> : Type extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteral<Value> : Type extends TNumber ? ['[number]'] : Type extends TInteger ? ['[number]'] : [
11
+ ]);
12
12
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
13
13
  export declare function IndexPropertyKeys<Type extends TSchema>(type: Type): TIndexPropertyKeys<Type>;
14
14
  export {};
@@ -9,19 +9,19 @@ const index_1 = require("../template-literal/index");
9
9
  const kind_1 = require("../guard/kind");
10
10
  // prettier-ignore
11
11
  function FromTemplateLiteral(templateLiteral) {
12
- const result = (0, index_1.TemplateLiteralGenerate)(templateLiteral);
13
- return result.map(S => S.toString());
12
+ const keys = (0, index_1.TemplateLiteralGenerate)(templateLiteral);
13
+ return keys.map(key => key.toString());
14
14
  }
15
15
  // prettier-ignore
16
- function FromUnion(type) {
16
+ function FromUnion(types) {
17
17
  const result = [];
18
- for (const left of type)
19
- result.push(...IndexPropertyKeys(left));
18
+ for (const type of types)
19
+ result.push(...IndexPropertyKeys(type));
20
20
  return result;
21
21
  }
22
22
  // prettier-ignore
23
- function FromLiteral(T) {
24
- return ([T.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
23
+ function FromLiteral(literalValue) {
24
+ return ([literalValue.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
25
25
  );
26
26
  }
27
27
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
@@ -1,54 +1,52 @@
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';
4
- import { type TObject, type TProperties } from '../object/index';
5
2
  import { type Assert } from '../helpers/index';
3
+ import { type TComputed } from '../computed/index';
6
4
  import { type TNever } from '../never/index';
7
- import { type TRecursive } from '../recursive/index';
5
+ import { type TArray } from '../array/index';
8
6
  import { type TIntersect } from '../intersect/index';
9
- import { TMappedResult, type TMappedKey } from '../mapped/index';
7
+ import { type TMappedResult, type TMappedKey } from '../mapped/index';
8
+ import { type TObject, type TProperties } from '../object/index';
10
9
  import { type TUnion } from '../union/index';
11
- import { type TTuple } from '../tuple/index';
12
- import { type TArray } from '../array/index';
10
+ import { type TRecursive } from '../recursive/index';
13
11
  import { type TRef } from '../ref/index';
12
+ import { type TTuple } from '../tuple/index';
14
13
  import { type TIntersectEvaluated } from '../intersect/index';
15
14
  import { type TUnionEvaluated } from '../union/index';
16
15
  import { type TIndexPropertyKeys } from './indexed-property-keys';
17
16
  import { type TIndexFromMappedKey } from './indexed-from-mapped-key';
18
17
  import { type TIndexFromMappedResult } from './indexed-from-mapped-result';
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);
18
+ type TFromRest<Types extends TSchema[], Key extends PropertyKey, Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<Right, Key, [...Result, Assert<TIndexFromPropertyKey<Left, Key>, TSchema>]> : Result);
20
19
  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
20
  type TFromIntersect<Types extends TSchema[], Key extends PropertyKey> = (TIntersectEvaluated<TFromIntersectRest<TFromRest<Types, Key>>>);
22
21
  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
22
  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;
23
+ type TFromTuple<Types extends TSchema[], Key extends PropertyKey> = (Key extends keyof Types ? Types[Key] : Key extends '[number]' ? TUnionEvaluated<Types> : TNever);
25
24
  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>;
25
+ type AssertPropertyKey<T> = Assert<T, string | number>;
26
+ type TFromProperty<Properties extends TProperties, Key extends PropertyKey> = (Key extends keyof Properties ? Properties[Key] : `${AssertPropertyKey<Key>}` extends `${AssertPropertyKey<keyof Properties>}` ? Properties[AssertPropertyKey<Key>] : TNever);
27
+ export type TIndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey> = (Type extends TRecursive<infer Type extends TSchema> ? TIndexFromPropertyKey<Type, Key> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<Types, Key> : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<Types, Key> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<Types, Key> : Type extends TArray<infer Type extends TSchema> ? TFromArray<Type, Key> : Type extends TObject<infer Properties extends TProperties> ? TFromProperty<Properties, Key> : TNever);
28
+ export declare function IndexFromPropertyKey<Type extends TSchema, Key extends PropertyKey>(type: Type, propertyKey: Key): TIndexFromPropertyKey<Type, Key>;
30
29
  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
30
  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>>);
46
- /** `[Json]` Returns an Indexed property type for the given keys */
47
- export declare function Index<Type extends TSchema, Key extends PropertyKey[]>(type: Type, key: readonly [...Key], options?: SchemaOptions): TIndex<Type, Key>;
48
- /** `[Json]` Returns an Indexed property type for the given keys */
49
- export declare function Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
50
- /** `[Json]` Returns an Indexed property type for the given keys */
51
- export declare function Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
52
- /** `[Json]` Returns an Indexed property type for the given keys */
53
- export declare function Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
31
+ type FromSchema<Type extends TSchema, PropertyKeys extends PropertyKey[]> = (TUnionEvaluated<TIndexFromPropertyKeys<Type, PropertyKeys>>);
32
+ declare function FromSchema<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: [...PropertyKeys]): FromSchema<Type, PropertyKeys>;
33
+ export type TIndexFromComputed<Type extends TSchema, Key extends TSchema> = (TComputed<'Index', [Type, Key]>);
34
+ export declare function IndexFromComputed<Type extends TSchema, Key extends TSchema>(type: Type, key: Key): TIndexFromComputed<Type, Key>;
35
+ export type TIndex<Type extends TSchema, PropertyKeys extends PropertyKey[]> = (FromSchema<Type, PropertyKeys>);
36
+ /** `[Json]` Returns an Indexed property type for the given keys */
37
+ export declare function Index<Type extends TRef, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
38
+ /** `[Json]` Returns an Indexed property type for the given keys */
39
+ export declare function Index<Type extends TSchema, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
40
+ /** `[Json]` Returns an Indexed property type for the given keys */
41
+ export declare function Index<Type extends TRef, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
42
+ /** `[Json]` Returns an Indexed property type for the given keys */
43
+ export declare function Index<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TIndexFromMappedResult<Type, MappedResult>;
44
+ /** `[Json]` Returns an Indexed property type for the given keys */
45
+ export declare function Index<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TIndexFromMappedResult<Type, MappedResult>;
46
+ /** `[Json]` Returns an Indexed property type for the given keys */
47
+ export declare function Index<Type extends TSchema, MappedKey extends TMappedKey>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TIndexFromMappedKey<Type, MappedKey>;
48
+ /** `[Json]` Returns an Indexed property type for the given keys */
49
+ export declare function Index<Type extends TSchema, Key extends TSchema, PropertyKeys extends PropertyKey[] = TIndexPropertyKeys<Key>>(T: Type, K: Key, options?: SchemaOptions): TIndex<Type, PropertyKeys>;
50
+ /** `[Json]` Returns an Indexed property type for the given keys */
51
+ export declare function Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
54
52
  export {};
@@ -3,31 +3,28 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.IndexFromPropertyKey = IndexFromPropertyKey;
5
5
  exports.IndexFromPropertyKeys = IndexFromPropertyKeys;
6
+ exports.IndexFromComputed = IndexFromComputed;
6
7
  exports.Index = Index;
7
8
  const type_1 = require("../create/type");
8
- const index_1 = require("../computed/index");
9
- const index_2 = require("../literal/index");
9
+ const index_1 = require("../error/index");
10
+ const index_2 = require("../computed/index");
10
11
  const index_3 = require("../never/index");
11
12
  const index_4 = require("../intersect/index");
12
13
  const index_5 = require("../union/index");
13
- // ------------------------------------------------------------------
14
- // Infrastructure
15
- // ------------------------------------------------------------------
16
14
  const indexed_property_keys_1 = require("./indexed-property-keys");
17
15
  const indexed_from_mapped_key_1 = require("./indexed-from-mapped-key");
18
16
  const indexed_from_mapped_result_1 = require("./indexed-from-mapped-result");
19
17
  // ------------------------------------------------------------------
20
- // KindGuard
18
+ // TypeGuard
21
19
  // ------------------------------------------------------------------
22
20
  const kind_1 = require("../guard/kind");
23
- const value_1 = require("../guard/value");
24
21
  // prettier-ignore
25
22
  function FromRest(types, key) {
26
- return types.map(left => IndexFromPropertyKey(left, key));
23
+ return types.map(type => IndexFromPropertyKey(type, key));
27
24
  }
28
25
  // prettier-ignore
29
26
  function FromIntersectRest(types) {
30
- return types.filter(left => !(0, kind_1.IsNever)(left));
27
+ return types.filter(type => !(0, kind_1.IsNever)(type));
31
28
  }
32
29
  // prettier-ignore
33
30
  function FromIntersect(types, key) {
@@ -45,53 +42,57 @@ function FromUnion(types, key) {
45
42
  }
46
43
  // prettier-ignore
47
44
  function FromTuple(types, key) {
48
- return (key === '[number]' ? (0, index_5.UnionEvaluated)(types) :
49
- key in types ? types[key] :
45
+ return (key in types ? types[key] :
46
+ key === '[number]' ? (0, index_5.UnionEvaluated)(types) :
50
47
  (0, index_3.Never)());
51
48
  }
52
49
  // prettier-ignore
53
50
  function FromArray(type, key) {
54
- // ... ?
55
- return (key === '[number]' ? type : (0, index_3.Never)());
51
+ return (key === '[number]'
52
+ ? type
53
+ : (0, index_3.Never)());
56
54
  }
57
55
  // prettier-ignore
58
- function FromProperty(properties, key) {
59
- return (key in properties ? properties[key] : (0, index_3.Never)());
56
+ function FromProperty(properties, propertyKey) {
57
+ return (propertyKey in properties ? properties[propertyKey] : (0, index_3.Never)());
60
58
  }
61
59
  // prettier-ignore
62
- function IndexFromPropertyKey(type, key) {
63
- return ((0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf, key) :
64
- (0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf, key) :
65
- (0, kind_1.IsTuple)(type) ? FromTuple(type.items ?? [], key) :
66
- (0, kind_1.IsArray)(type) ? FromArray(type.items, key) :
67
- (0, kind_1.IsObject)(type) ? FromProperty(type.properties, key) :
60
+ function IndexFromPropertyKey(type, propertyKey) {
61
+ return ((0, kind_1.IsIntersect)(type) ? FromIntersect(type.allOf, propertyKey) :
62
+ (0, kind_1.IsUnion)(type) ? FromUnion(type.anyOf, propertyKey) :
63
+ (0, kind_1.IsTuple)(type) ? FromTuple(type.items ?? [], propertyKey) :
64
+ (0, kind_1.IsArray)(type) ? FromArray(type.items, propertyKey) :
65
+ (0, kind_1.IsObject)(type) ? FromProperty(type.properties, propertyKey) :
68
66
  (0, index_3.Never)());
69
67
  }
70
68
  // prettier-ignore
71
69
  function IndexFromPropertyKeys(type, propertyKeys) {
72
- return propertyKeys.map(left => IndexFromPropertyKey(type, left));
70
+ return propertyKeys.map(propertyKey => IndexFromPropertyKey(type, propertyKey));
73
71
  }
74
72
  // prettier-ignore
75
- function FromType(type, propertyKeys) {
76
- const result = IndexFromPropertyKeys(type, propertyKeys);
77
- return (0, index_5.UnionEvaluated)(result);
73
+ function FromSchema(type, propertyKeys) {
74
+ return ((0, index_5.UnionEvaluated)(IndexFromPropertyKeys(type, propertyKeys)));
78
75
  }
79
76
  // prettier-ignore
80
- function UnionFromPropertyKeys(propertyKeys) {
81
- const result = propertyKeys.reduce((result, key) => (0, kind_1.IsLiteralValue)(key) ? [...result, (0, index_2.Literal)(key)] : result, []);
82
- return (0, index_5.UnionEvaluated)(result);
77
+ function IndexFromComputed(type, key) {
78
+ return (0, index_2.Computed)('Index', [type, key]);
83
79
  }
84
80
  /** `[Json]` Returns an Indexed property type for the given keys */
85
- // prettier-ignore
86
81
  function Index(type, key, options) {
87
- const typeKey = (0, value_1.IsArray)(key) ? UnionFromPropertyKeys(key) : key;
88
- const propertyKeys = (0, kind_1.IsSchema)(key) ? (0, indexed_property_keys_1.IndexPropertyKeys)(key) : key;
89
- const isTypeRef = (0, kind_1.IsRef)(type);
90
- const isKeyRef = (0, kind_1.IsRef)(key);
91
- return ((0, kind_1.IsMappedResult)(key) ? (0, indexed_from_mapped_result_1.IndexFromMappedResult)(type, key, options) :
92
- (0, kind_1.IsMappedKey)(key) ? (0, indexed_from_mapped_key_1.IndexFromMappedKey)(type, key, options) :
93
- (isTypeRef && isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
94
- (!isTypeRef && isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
95
- (isTypeRef && !isKeyRef) ? (0, index_1.Computed)('Index', [type, typeKey], options) :
96
- (0, type_1.CreateType)(FromType(type, propertyKeys), options));
82
+ // computed-type
83
+ if ((0, kind_1.IsRef)(type) || (0, kind_1.IsRef)(key)) {
84
+ const error = `Index types using Ref parameters require both Type and Key to be of TSchema`;
85
+ if (!(0, kind_1.IsSchema)(type) || !(0, kind_1.IsSchema)(key))
86
+ throw new index_1.TypeBoxError(error);
87
+ return (0, index_2.Computed)('Index', [type, key]);
88
+ }
89
+ // mapped-types
90
+ if ((0, kind_1.IsMappedResult)(key))
91
+ return (0, indexed_from_mapped_result_1.IndexFromMappedResult)(type, key, options);
92
+ if ((0, kind_1.IsMappedKey)(key))
93
+ return (0, indexed_from_mapped_key_1.IndexFromMappedKey)(type, key, options);
94
+ // prettier-ignore
95
+ return (0, type_1.CreateType)((0, kind_1.IsSchema)(key)
96
+ ? FromSchema(type, (0, indexed_property_keys_1.IndexPropertyKeys)(key))
97
+ : FromSchema(type, key), options);
97
98
  }
@@ -5,8 +5,8 @@ import { type TAwaited } from '../awaited/index';
5
5
  import { type TAsyncIterator } from '../async-iterator/index';
6
6
  import { TComputed } from '../computed/index';
7
7
  import { type TConstructor } from '../constructor/index';
8
- import { type TIndex } from '../indexed/index';
9
- import { TEnum, TEnumRecord } from '../enum/index';
8
+ import { type TIndex, type TIndexPropertyKeys } from '../indexed/index';
9
+ import { TEnum, type TEnumRecord } from '../enum/index';
10
10
  import { type TFunction } from '../function/index';
11
11
  import { type TIntersect, type TIntersectEvaluated } from '../intersect/index';
12
12
  import { type TIterator } from '../iterator/index';
@@ -26,7 +26,7 @@ import { type TUnion, type TUnionEvaluated } from '../union/index';
26
26
  type TDerefParameters<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef<infer Key extends string> ? TDerefParameters<ModuleProperties, Right, [...Result, TDeref<ModuleProperties, Key>]> : TDerefParameters<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
27
27
  type TDeref<ModuleProperties extends TProperties, Ref extends string, Result extends TSchema = (Ref extends keyof ModuleProperties ? ModuleProperties[Ref] extends TRef<infer Ref2 extends string> ? TDeref<ModuleProperties, Ref2> : TFromType<ModuleProperties, ModuleProperties[Ref]> : TNever)> = Result;
28
28
  type TFromAwaited<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TAwaited<T0> : never);
29
- type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, T1> : never);
29
+ type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, TIndexPropertyKeys<T1>> extends infer Result extends TSchema ? Result : never : never);
30
30
  type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TKeyOf<T0> : never);
31
31
  type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TPartial<T0> : never);
32
32
  type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
@@ -133,9 +133,6 @@ function FromType(moduleProperties, type) {
133
133
  // Traveral
134
134
  KindGuard.IsArray(type) ? (0, index_1.CreateType)(FromArray(moduleProperties, type.items), type) :
135
135
  KindGuard.IsAsyncIterator(type) ? (0, index_1.CreateType)(FromAsyncIterator(moduleProperties, type.items), type) :
136
- // Note: The 'as never' is required due to excessive resolution of TIndex. In fact TIndex, TPick, TOmit and
137
- // all need re-implementation to remove the PropertyKey[] selector. Reimplementation of these types should
138
- // be a priority as there is a potential for the current inference to break on TS compiler changes.
139
136
  KindGuard.IsComputed(type) ? (0, index_1.CreateType)(FromComputed(moduleProperties, type.target, type.parameters)) :
140
137
  KindGuard.IsConstructor(type) ? (0, index_1.CreateType)(FromConstructor(moduleProperties, type.parameters, type.returns), type) :
141
138
  KindGuard.IsFunction(type) ? (0, index_1.CreateType)(FromFunction(moduleProperties, type.parameters, type.returns), type) :
@@ -37,7 +37,9 @@ type InferProperties<ModuleProperties extends TProperties, Properties extends TP
37
37
  }>;
38
38
  type TInferObject<ModuleProperties extends TProperties, Properties extends TProperties> = (InferProperties<ModuleProperties, Properties>);
39
39
  type TInferTuple<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown[] = []> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferTuple<ModuleProperties, R, [...Result, TInfer<ModuleProperties, L>]> : Result);
40
- type TInferRecord<ModuleProperties extends TProperties, Key extends TSchema, Type extends TSchema, InferredKey extends PropertyKey = TInfer<ModuleProperties, Key> extends infer Key extends PropertyKey ? Key : never, InferedType extends unknown = TInfer<ModuleProperties, Type>> = Record<InferredKey, InferedType>;
40
+ type TInferRecord<ModuleProperties extends TProperties, Key extends TSchema, Type extends TSchema, InferredKey extends PropertyKey = TInfer<ModuleProperties, Key> extends infer Key extends PropertyKey ? Key : never, InferedType extends unknown = TInfer<ModuleProperties, Type>> = Ensure<{
41
+ [_ in InferredKey]: InferedType;
42
+ }>;
41
43
  type TInferRef<ModuleProperties extends TProperties, Ref extends string> = (Ref extends keyof ModuleProperties ? TInfer<ModuleProperties, ModuleProperties[Ref]> : unknown);
42
44
  type TInferUnion<ModuleProperties extends TProperties, Types extends TSchema[], Result extends unknown = never> = (Types extends [infer L extends TSchema, ...infer R extends TSchema[]] ? TInferUnion<ModuleProperties, R, Result | TInfer<ModuleProperties, L>> : Result);
43
45
  type TInfer<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TArray<infer Type extends TSchema> ? TInferArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TInferAsyncIterator<ModuleProperties, Type> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TInferConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TInferFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TInferIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TInferIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TInferObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Type extends TSchema> ? TInferRecord<ModuleProperties, Key, Type> : Type extends TRef<infer Ref extends string> ? TInferRef<ModuleProperties, Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TInferTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Static<Type> : Type extends TUnion<infer Types extends TSchema[]> ? TInferUnion<ModuleProperties, Types> : Static<Type>);
@@ -52,7 +52,7 @@ export interface TRecord<Key extends TSchema = TSchema, Type extends TSchema = T
52
52
  };
53
53
  additionalProperties: TAdditionalProperties;
54
54
  }
55
- export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : Key);
55
+ export type TRecordOrObject<Key extends TSchema, Type extends TSchema> = (Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [Key, TComputed<Target, Parameters>]> : Key extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TComputed<'Record', [TComputed<Target, Parameters>, Type]> : Key extends TRef<infer Ref extends string> ? TComputed<'Record', [TRef<Ref>, Type]> : Key extends TTemplateLiteral ? TFromTemplateLiteralKey<Key, Type> : Key extends TEnum<infer Enum extends TEnumRecord> ? TFromEnumKey<Enum, Type> : Key extends TUnion<infer Types extends TSchema[]> ? TFromUnionKey<Types, Type> : Key extends TLiteral<infer Value extends TLiteralValue> ? TFromLiteralKey<Value, Type> : Key extends TInteger ? TFromIntegerKey<Key, Type> : Key extends TNumber ? TFromNumberKey<Key, Type> : Key extends TRegExp ? TFromRegExpKey<Key, Type> : Key extends TString ? TFromStringKey<Key, Type> : Key extends TAny ? TFromAnyKey<Key, Type> : Key extends TNever ? TFromNeverKey<Key, Type> : TNever);
56
56
  /** `[Json]` Creates a Record type */
57
57
  export declare function Record<Key extends TSchema, Type extends TSchema>(key: Key, type: Type, options?: ObjectOptions): TRecordOrObject<Key, Type>;
58
58
  export {};