@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.
@@ -7,7 +7,7 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index';
7
7
  import { type TExclude, type TExcludeFromMappedResult, type TExcludeFromTemplateLiteral } from '../exclude/index';
8
8
  import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index';
9
9
  import { type TExtract, type TExtractFromMappedResult, type TExtractFromTemplateLiteral } from '../extract/index';
10
- import { TIndex, type TIndexPropertyKeys } from '../indexed/index';
10
+ import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult, type TIndexFromComputed } from '../indexed/index';
11
11
  import { type IntegerOptions, type TInteger } from '../integer/index';
12
12
  import { Intersect, type IntersectOptions } from '../intersect/index';
13
13
  import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index';
@@ -93,13 +93,19 @@ export declare class JsonTypeBuilder {
93
93
  /** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
94
94
  Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
95
95
  /** `[Json]` Returns an Indexed property type for the given keys */
96
- Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, key: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
96
+ Index<Type extends TRef, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
97
97
  /** `[Json]` Returns an Indexed property type for the given keys */
98
- Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
98
+ Index<Type extends TSchema, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
99
99
  /** `[Json]` Returns an Indexed property type for the given keys */
100
- Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
100
+ Index<Type extends TRef, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
101
101
  /** `[Json]` Returns an Indexed property type for the given keys */
102
- Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
102
+ Index<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TIndexFromMappedResult<Type, MappedResult>;
103
+ /** `[Json]` Returns an Indexed property type for the given keys */
104
+ Index<Type extends TSchema, MappedKey extends TMappedKey>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TIndexFromMappedKey<Type, MappedKey>;
105
+ /** `[Json]` Returns an Indexed property type for the given keys */
106
+ Index<Type extends TSchema, Key extends TSchema, PropertyKeys extends PropertyKey[] = TIndexPropertyKeys<Key>>(T: Type, K: Key, options?: SchemaOptions): TIndex<Type, PropertyKeys>;
107
+ /** `[Json]` Returns an Indexed property type for the given keys */
108
+ Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
103
109
  /** `[Json]` Creates an Integer type */
104
110
  Integer(options?: IntegerOptions): TInteger;
105
111
  /** `[Json]` Creates an Intersect type */
@@ -4,7 +4,7 @@ import { StaticDecode } from '../../type/static/index';
4
4
  export declare class ParseError extends TypeBoxError {
5
5
  constructor(message: string);
6
6
  }
7
- export type TParseOperation = 'Clone' | 'Clean' | 'Default' | 'Convert' | 'Assert' | 'Decode' | ({} & string);
7
+ export type TParseOperation = 'Clone' | 'Clean' | 'Default' | 'Convert' | 'Assert' | 'Decode' | 'Encode' | ({} & string);
8
8
  export type TParseFunction = (type: TSchema, references: TSchema[], value: unknown) => unknown;
9
9
  export declare namespace ParseRegistry {
10
10
  function Delete(key: string): void;
@@ -9,6 +9,7 @@ import { TypeRegistry, FormatRegistry } from '../type/registry/index.mjs';
9
9
  import { KeyOfPattern } from '../type/keyof/index.mjs';
10
10
  import { ExtendsUndefinedCheck } from '../type/extends/extends-undefined.mjs';
11
11
  import { Never } from '../type/never/index.mjs';
12
+ import { Ref } from '../type/ref/index.mjs';
12
13
  // ------------------------------------------------------------------
13
14
  // ValueGuard
14
15
  // ------------------------------------------------------------------
@@ -264,9 +265,10 @@ export var TypeCompiler;
264
265
  yield `(typeof ${value} === 'function')`;
265
266
  }
266
267
  function* FromImport(schema, references, value) {
267
- const definitions = globalThis.Object.values(schema.$defs);
268
- const target = schema.$defs[schema.$ref];
269
- yield* Visit(target, [...references, ...definitions], value);
268
+ const members = globalThis.Object.getOwnPropertyNames(schema.$defs).reduce((result, key) => {
269
+ return [...result, schema.$defs[key]];
270
+ }, []);
271
+ yield* Visit(Ref(schema.$ref), [...references, ...members], value);
270
272
  }
271
273
  function* FromInteger(schema, references, value) {
272
274
  yield `Number.isInteger(${value})`;
@@ -385,13 +387,9 @@ export var TypeCompiler;
385
387
  function* FromRef(schema, references, value) {
386
388
  const target = Deref(schema, references);
387
389
  // Reference: If we have seen this reference before we can just yield and return the function call.
388
- // If this isn't the case we defer to visit to generate and set the _recursion_end_for_ for subsequent
389
- // passes. This operation is very awkward as we are using the functions state to store values to
390
- // enable self referential types to terminate. This needs to be refactored.
391
- const recursiveEnd = `_recursion_end_for_${schema.$ref}`;
392
- if (state.functions.has(recursiveEnd))
390
+ // If this isn't the case we defer to visit to generate and set the function for subsequent passes.
391
+ if (state.functions.has(schema.$ref))
393
392
  return yield `${CreateFunctionName(schema.$ref)}(${value})`;
394
- state.functions.set(recursiveEnd, ''); // terminate recursion here by setting the name.
395
393
  yield* Visit(target, references, value);
396
394
  }
397
395
  function* FromRegExp(schema, references, value) {
@@ -476,6 +474,10 @@ export var TypeCompiler;
476
474
  return yield `${functionName}(${value})`;
477
475
  }
478
476
  else {
477
+ // Note: In the case of cyclic types, we need to create a 'functions' record
478
+ // to prevent infinitely re-visiting the CreateFunction. Subsequent attempts
479
+ // to visit will be caught by the above condition.
480
+ state.functions.set(functionName, '<deferred>');
479
481
  const functionCode = CreateFunction(functionName, schema, references, 'value', false);
480
482
  state.functions.set(functionName, functionCode);
481
483
  return yield `${functionName}(${value})`;
@@ -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[]>>;
@@ -5,8 +5,7 @@ import { Index } from './index.mjs';
5
5
  function FromProperties(type, properties, options) {
6
6
  const result = {};
7
7
  for (const K2 of Object.getOwnPropertyNames(properties)) {
8
- const keys = IndexPropertyKeys(properties[K2]);
9
- result[K2] = Index(type, keys, options);
8
+ result[K2] = Index(type, IndexPropertyKeys(properties[K2]), options);
10
9
  }
11
10
  return result;
12
11
  }
@@ -4,11 +4,11 @@ import type { TInteger } from '../integer/index.mjs';
4
4
  import type { TNumber } from '../number/index.mjs';
5
5
  import type { TSchema } from '../schema/index.mjs';
6
6
  import type { TUnion } from '../union/index.mjs';
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 {};
@@ -5,19 +5,19 @@ import { TemplateLiteralGenerate } from '../template-literal/index.mjs';
5
5
  import { IsTemplateLiteral, IsUnion, IsLiteral, IsNumber, IsInteger } from '../guard/kind.mjs';
6
6
  // prettier-ignore
7
7
  function FromTemplateLiteral(templateLiteral) {
8
- const result = TemplateLiteralGenerate(templateLiteral);
9
- return result.map(S => S.toString());
8
+ const keys = TemplateLiteralGenerate(templateLiteral);
9
+ return keys.map(key => key.toString());
10
10
  }
11
11
  // prettier-ignore
12
- function FromUnion(type) {
12
+ function FromUnion(types) {
13
13
  const result = [];
14
- for (const left of type)
15
- result.push(...IndexPropertyKeys(left));
14
+ for (const type of types)
15
+ result.push(...IndexPropertyKeys(type));
16
16
  return result;
17
17
  }
18
18
  // prettier-ignore
19
- function FromLiteral(T) {
20
- return ([T.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
19
+ function FromLiteral(literalValue) {
20
+ return ([literalValue.toString()] // TS 5.4 observes TLiteralValue as not having a toString()
21
21
  );
22
22
  }
23
23
  /** Returns a tuple of PropertyKeys derived from the given TSchema */
@@ -1,54 +1,52 @@
1
1
  import { type TSchema, SchemaOptions } from '../schema/index.mjs';
2
- import { type TComputed } from '../computed/index.mjs';
3
- import { type TLiteral, type TLiteralValue } from '../literal/index.mjs';
4
- import { type TObject, type TProperties } from '../object/index.mjs';
5
2
  import { type Assert } from '../helpers/index.mjs';
3
+ import { type TComputed } from '../computed/index.mjs';
6
4
  import { type TNever } from '../never/index.mjs';
7
- import { type TRecursive } from '../recursive/index.mjs';
5
+ import { type TArray } from '../array/index.mjs';
8
6
  import { type TIntersect } from '../intersect/index.mjs';
9
- import { TMappedResult, type TMappedKey } from '../mapped/index.mjs';
7
+ import { type TMappedResult, type TMappedKey } from '../mapped/index.mjs';
8
+ import { type TObject, type TProperties } from '../object/index.mjs';
10
9
  import { type TUnion } from '../union/index.mjs';
11
- import { type TTuple } from '../tuple/index.mjs';
12
- import { type TArray } from '../array/index.mjs';
10
+ import { type TRecursive } from '../recursive/index.mjs';
13
11
  import { type TRef } from '../ref/index.mjs';
12
+ import { type TTuple } from '../tuple/index.mjs';
14
13
  import { type TIntersectEvaluated } from '../intersect/index.mjs';
15
14
  import { type TUnionEvaluated } from '../union/index.mjs';
16
15
  import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
17
16
  import { type TIndexFromMappedKey } from './indexed-from-mapped-key.mjs';
18
17
  import { type TIndexFromMappedResult } from './indexed-from-mapped-result.mjs';
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 {};
@@ -1,27 +1,23 @@
1
1
  import { CreateType } from '../create/type.mjs';
2
+ import { TypeBoxError } from '../error/index.mjs';
2
3
  import { Computed } from '../computed/index.mjs';
3
- import { Literal } from '../literal/index.mjs';
4
4
  import { Never } from '../never/index.mjs';
5
5
  import { IntersectEvaluated } from '../intersect/index.mjs';
6
6
  import { UnionEvaluated } from '../union/index.mjs';
7
- // ------------------------------------------------------------------
8
- // Infrastructure
9
- // ------------------------------------------------------------------
10
7
  import { IndexPropertyKeys } from './indexed-property-keys.mjs';
11
8
  import { IndexFromMappedKey } from './indexed-from-mapped-key.mjs';
12
9
  import { IndexFromMappedResult } from './indexed-from-mapped-result.mjs';
13
10
  // ------------------------------------------------------------------
14
- // KindGuard
11
+ // TypeGuard
15
12
  // ------------------------------------------------------------------
16
- import { IsArray, IsIntersect, IsObject, IsMappedKey, IsMappedResult, IsNever, IsSchema, IsTuple, IsUnion, IsLiteralValue, IsRef } from '../guard/kind.mjs';
17
- import { IsArray as IsArrayValue } from '../guard/value.mjs';
13
+ import { IsArray, IsIntersect, IsObject, IsMappedKey, IsMappedResult, IsNever, IsSchema, IsTuple, IsUnion, IsRef } from '../guard/kind.mjs';
18
14
  // prettier-ignore
19
15
  function FromRest(types, key) {
20
- return types.map(left => IndexFromPropertyKey(left, key));
16
+ return types.map(type => IndexFromPropertyKey(type, key));
21
17
  }
22
18
  // prettier-ignore
23
19
  function FromIntersectRest(types) {
24
- return types.filter(left => !IsNever(left));
20
+ return types.filter(type => !IsNever(type));
25
21
  }
26
22
  // prettier-ignore
27
23
  function FromIntersect(types, key) {
@@ -39,53 +35,57 @@ function FromUnion(types, key) {
39
35
  }
40
36
  // prettier-ignore
41
37
  function FromTuple(types, key) {
42
- return (key === '[number]' ? UnionEvaluated(types) :
43
- key in types ? types[key] :
38
+ return (key in types ? types[key] :
39
+ key === '[number]' ? UnionEvaluated(types) :
44
40
  Never());
45
41
  }
46
42
  // prettier-ignore
47
43
  function FromArray(type, key) {
48
- // ... ?
49
- return (key === '[number]' ? type : Never());
44
+ return (key === '[number]'
45
+ ? type
46
+ : Never());
50
47
  }
51
48
  // prettier-ignore
52
- function FromProperty(properties, key) {
53
- return (key in properties ? properties[key] : Never());
49
+ function FromProperty(properties, propertyKey) {
50
+ return (propertyKey in properties ? properties[propertyKey] : Never());
54
51
  }
55
52
  // prettier-ignore
56
- export function IndexFromPropertyKey(type, key) {
57
- return (IsIntersect(type) ? FromIntersect(type.allOf, key) :
58
- IsUnion(type) ? FromUnion(type.anyOf, key) :
59
- IsTuple(type) ? FromTuple(type.items ?? [], key) :
60
- IsArray(type) ? FromArray(type.items, key) :
61
- IsObject(type) ? FromProperty(type.properties, key) :
53
+ export function IndexFromPropertyKey(type, propertyKey) {
54
+ return (IsIntersect(type) ? FromIntersect(type.allOf, propertyKey) :
55
+ IsUnion(type) ? FromUnion(type.anyOf, propertyKey) :
56
+ IsTuple(type) ? FromTuple(type.items ?? [], propertyKey) :
57
+ IsArray(type) ? FromArray(type.items, propertyKey) :
58
+ IsObject(type) ? FromProperty(type.properties, propertyKey) :
62
59
  Never());
63
60
  }
64
61
  // prettier-ignore
65
62
  export function IndexFromPropertyKeys(type, propertyKeys) {
66
- return propertyKeys.map(left => IndexFromPropertyKey(type, left));
63
+ return propertyKeys.map(propertyKey => IndexFromPropertyKey(type, propertyKey));
67
64
  }
68
65
  // prettier-ignore
69
- function FromType(type, propertyKeys) {
70
- const result = IndexFromPropertyKeys(type, propertyKeys);
71
- return UnionEvaluated(result);
66
+ function FromSchema(type, propertyKeys) {
67
+ return (UnionEvaluated(IndexFromPropertyKeys(type, propertyKeys)));
72
68
  }
73
69
  // prettier-ignore
74
- function UnionFromPropertyKeys(propertyKeys) {
75
- const result = propertyKeys.reduce((result, key) => IsLiteralValue(key) ? [...result, Literal(key)] : result, []);
76
- return UnionEvaluated(result);
70
+ export function IndexFromComputed(type, key) {
71
+ return Computed('Index', [type, key]);
77
72
  }
78
73
  /** `[Json]` Returns an Indexed property type for the given keys */
79
- // prettier-ignore
80
74
  export function Index(type, key, options) {
81
- const typeKey = IsArrayValue(key) ? UnionFromPropertyKeys(key) : key;
82
- const propertyKeys = IsSchema(key) ? IndexPropertyKeys(key) : key;
83
- const isTypeRef = IsRef(type);
84
- const isKeyRef = IsRef(key);
85
- return (IsMappedResult(key) ? IndexFromMappedResult(type, key, options) :
86
- IsMappedKey(key) ? IndexFromMappedKey(type, key, options) :
87
- (isTypeRef && isKeyRef) ? Computed('Index', [type, typeKey], options) :
88
- (!isTypeRef && isKeyRef) ? Computed('Index', [type, typeKey], options) :
89
- (isTypeRef && !isKeyRef) ? Computed('Index', [type, typeKey], options) :
90
- CreateType(FromType(type, propertyKeys), options));
75
+ // computed-type
76
+ if (IsRef(type) || IsRef(key)) {
77
+ const error = `Index types using Ref parameters require both Type and Key to be of TSchema`;
78
+ if (!IsSchema(type) || !IsSchema(key))
79
+ throw new TypeBoxError(error);
80
+ return Computed('Index', [type, key]);
81
+ }
82
+ // mapped-types
83
+ if (IsMappedResult(key))
84
+ return IndexFromMappedResult(type, key, options);
85
+ if (IsMappedKey(key))
86
+ return IndexFromMappedKey(type, key, options);
87
+ // prettier-ignore
88
+ return CreateType(IsSchema(key)
89
+ ? FromSchema(type, IndexPropertyKeys(key))
90
+ : FromSchema(type, key), options);
91
91
  }
@@ -5,8 +5,8 @@ import { type TAwaited } from '../awaited/index.mjs';
5
5
  import { type TAsyncIterator } from '../async-iterator/index.mjs';
6
6
  import { TComputed } from '../computed/index.mjs';
7
7
  import { type TConstructor } from '../constructor/index.mjs';
8
- import { type TIndex } from '../indexed/index.mjs';
9
- import { TEnum, TEnumRecord } from '../enum/index.mjs';
8
+ import { type TIndex, type TIndexPropertyKeys } from '../indexed/index.mjs';
9
+ import { TEnum, type TEnumRecord } from '../enum/index.mjs';
10
10
  import { type TFunction } from '../function/index.mjs';
11
11
  import { type TIntersect, type TIntersectEvaluated } from '../intersect/index.mjs';
12
12
  import { type TIterator } from '../iterator/index.mjs';
@@ -26,7 +26,7 @@ import { type TUnion, type TUnionEvaluated } from '../union/index.mjs';
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);
@@ -127,9 +127,6 @@ export function FromType(moduleProperties, type) {
127
127
  // Traveral
128
128
  KindGuard.IsArray(type) ? CreateType(FromArray(moduleProperties, type.items), type) :
129
129
  KindGuard.IsAsyncIterator(type) ? CreateType(FromAsyncIterator(moduleProperties, type.items), type) :
130
- // Note: The 'as never' is required due to excessive resolution of TIndex. In fact TIndex, TPick, TOmit and
131
- // all need re-implementation to remove the PropertyKey[] selector. Reimplementation of these types should
132
- // be a priority as there is a potential for the current inference to break on TS compiler changes.
133
130
  KindGuard.IsComputed(type) ? CreateType(FromComputed(moduleProperties, type.target, type.parameters)) :
134
131
  KindGuard.IsConstructor(type) ? CreateType(FromConstructor(moduleProperties, type.parameters, type.returns), type) :
135
132
  KindGuard.IsFunction(type) ? 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 {};
@@ -7,7 +7,7 @@ import { type TEnum, type TEnumKey, type TEnumValue } from '../enum/index.mjs';
7
7
  import { type TExclude, type TExcludeFromMappedResult, type TExcludeFromTemplateLiteral } from '../exclude/index.mjs';
8
8
  import { type TExtends, type TExtendsFromMappedKey, type TExtendsFromMappedResult } from '../extends/index.mjs';
9
9
  import { type TExtract, type TExtractFromMappedResult, type TExtractFromTemplateLiteral } from '../extract/index.mjs';
10
- import { TIndex, type TIndexPropertyKeys } from '../indexed/index.mjs';
10
+ import { TIndex, type TIndexPropertyKeys, type TIndexFromMappedKey, type TIndexFromMappedResult, type TIndexFromComputed } from '../indexed/index.mjs';
11
11
  import { type IntegerOptions, type TInteger } from '../integer/index.mjs';
12
12
  import { Intersect, type IntersectOptions } from '../intersect/index.mjs';
13
13
  import { type TCapitalize, type TUncapitalize, type TLowercase, type TUppercase } from '../intrinsic/index.mjs';
@@ -93,13 +93,19 @@ export declare class JsonTypeBuilder {
93
93
  /** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
94
94
  Extract<L extends TSchema, R extends TSchema>(type: L, union: R, options?: SchemaOptions): TExtract<L, R>;
95
95
  /** `[Json]` Returns an Indexed property type for the given keys */
96
- Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, key: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
96
+ Index<Type extends TRef, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
97
97
  /** `[Json]` Returns an Indexed property type for the given keys */
98
- Index<Type extends TSchema, Key extends TMappedKey>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
98
+ Index<Type extends TSchema, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
99
99
  /** `[Json]` Returns an Indexed property type for the given keys */
100
- Index<Type extends TSchema, Key extends TMappedResult>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
100
+ Index<Type extends TRef, Key extends TRef>(type: Type, key: Key, options?: SchemaOptions): TIndexFromComputed<Type, Key>;
101
101
  /** `[Json]` Returns an Indexed property type for the given keys */
102
- Index<Type extends TSchema, Key extends TSchema>(type: Type, key: Key, options?: SchemaOptions): TIndex<Type, Key>;
102
+ Index<Type extends TSchema, MappedResult extends TMappedResult>(type: Type, mappedResult: MappedResult, options?: SchemaOptions): TIndexFromMappedResult<Type, MappedResult>;
103
+ /** `[Json]` Returns an Indexed property type for the given keys */
104
+ Index<Type extends TSchema, MappedKey extends TMappedKey>(type: Type, mappedKey: MappedKey, options?: SchemaOptions): TIndexFromMappedKey<Type, MappedKey>;
105
+ /** `[Json]` Returns an Indexed property type for the given keys */
106
+ Index<Type extends TSchema, Key extends TSchema, PropertyKeys extends PropertyKey[] = TIndexPropertyKeys<Key>>(T: Type, K: Key, options?: SchemaOptions): TIndex<Type, PropertyKeys>;
107
+ /** `[Json]` Returns an Indexed property type for the given keys */
108
+ Index<Type extends TSchema, PropertyKeys extends PropertyKey[]>(type: Type, propertyKeys: readonly [...PropertyKeys], options?: SchemaOptions): TIndex<Type, PropertyKeys>;
103
109
  /** `[Json]` Creates an Integer type */
104
110
  Integer(options?: IntegerOptions): TInteger;
105
111
  /** `[Json]` Creates an Intersect type */
@@ -4,7 +4,7 @@ import { StaticDecode } from '../../type/static/index.mjs';
4
4
  export declare class ParseError extends TypeBoxError {
5
5
  constructor(message: string);
6
6
  }
7
- export type TParseOperation = 'Clone' | 'Clean' | 'Default' | 'Convert' | 'Assert' | 'Decode' | ({} & string);
7
+ export type TParseOperation = 'Clone' | 'Clean' | 'Default' | 'Convert' | 'Assert' | 'Decode' | 'Encode' | ({} & string);
8
8
  export type TParseFunction = (type: TSchema, references: TSchema[], value: unknown) => unknown;
9
9
  export declare namespace ParseRegistry {
10
10
  function Delete(key: string): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sinclair/typebox",
3
- "version": "0.34.9",
3
+ "version": "0.34.11",
4
4
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
5
5
  "keywords": [
6
6
  "typescript",
package/readme.md CHANGED
@@ -1022,7 +1022,7 @@ if(TypeGuard.IsString(T)) {
1022
1022
 
1023
1023
  ## Syntax Types
1024
1024
 
1025
- Syntax Types is a feature that enables TypeBox to parse TypeScript type annotations directly into Json Schema. This feature works both at runtime and statically within the type system. Syntax Types use Json Schema as the Abstract Syntax Tree (AST) parse target for TypeScript types. Syntax Types are designed to offer a syntactical frontend to the standard Type Builder API.
1025
+ TypeBox has support for parsing TypeScript type annotations directly into TypeBox types. This feature supports both runtime and static parsing, with TypeBox implementing TypeScript parsers within the TypeScript type system itself. Syntax Types use the TypeBox Json Schema representations as an AST target for TypeScript types, providing a direct mapping between TypeScript syntax and Json Schema. Syntax Types are offered as a syntactical frontend to the Standard Type Builder API.
1026
1026
 
1027
1027
  This feature is available via optional import.
1028
1028
 
@@ -1051,7 +1051,7 @@ const C = Parse(`{ x: number, y: number }`) // const C: TObject<{
1051
1051
  // }>
1052
1052
  ```
1053
1053
 
1054
- Syntax Types can be composed with Standard Types.
1054
+ Syntax Types can compose with Standard Types created via the Type Builder API
1055
1055
 
1056
1056
  ```typescript
1057
1057
  const T = Type.Object({ // const T: TObject<{
@@ -1061,7 +1061,7 @@ const T = Type.Object({ // const T: TObject<{
1061
1061
  }) // }>
1062
1062
  ```
1063
1063
 
1064
- It is also possible to pass Standard Types to Syntax Types in the following way.
1064
+ Standard Types can also be passed to and referenced within Syntax Types.
1065
1065
 
1066
1066
  ```typescript
1067
1067
  const X = Type.Number()
@@ -1075,7 +1075,7 @@ const T = Parse({ X, Y, Z }, `{
1075
1075
  }`)
1076
1076
  ```
1077
1077
 
1078
- Syntax Types can also be used to parse Module types.
1078
+ Syntax Types also support Module parsing.
1079
1079
 
1080
1080
  ```typescript
1081
1081
  const Foo = Parse(`module Foo {
@@ -1127,7 +1127,7 @@ type T = StaticParseAsType<{}, '{ x: number }'> // type T = {
1127
1127
 
1128
1128
  ### Limitations
1129
1129
 
1130
- Syntax Types work by having TypeBox parse TypeScript syntax within the TypeScript type system. This approach can place some strain on the TypeScript compiler and language service, potentially affecting responsiveness. While TypeBox makes a best-effort attempt to optimize for Syntax Types, users should be mindful of the following structures:
1130
+ TypeBox parses TypeScript types directly within the TypeScript type system. This process does come with an inference cost, which scales with the size and complexity of the types being parsed. Although TypeBox strives to optimize Syntax Types, users should be aware of the following structures:
1131
1131
 
1132
1132
  ```typescript
1133
1133
  // Excessively wide structures will result in instantiation limits exceeding
@@ -1154,12 +1154,12 @@ const B = Parse(`{
1154
1154
  }`)
1155
1155
  ```
1156
1156
 
1157
- In cases where Syntax Types exceed TypeScript's instantiation limits, TypeBox offers a fallback ParseOnly function, which will only parse but not infer. This function can also be used to parse types where the syntax is statically unknown to TypeScript (for example, when loading types from disk).
1157
+ If Syntax Types exceed TypeScript's instantiation limits, users are advised to fall back to the Standard Type Builder API. Alternatively, TypeBox offers a `ParseOnly` function that parses the TypeScript syntax at runtime without statically inferring the schema.
1158
1158
 
1159
1159
  ```typescript
1160
1160
  import { ParseOnly } from '@sinclair/typebox/syntax'
1161
1161
 
1162
- // Where A is TSchema | undefined
1162
+ // const A: TSchema | undefined
1163
1163
 
1164
1164
  const A = ParseOnly(`{
1165
1165
  x: {
@@ -1172,7 +1172,7 @@ const A = ParseOnly(`{
1172
1172
  }`)
1173
1173
  ```
1174
1174
 
1175
- For more information on TypeBox's parsing infrastructure, refer to the [ParseBox](https://github.com/sinclairzx81/parsebox) project.
1175
+ For more information on static parsing, refer to the [ParseBox](https://github.com/sinclairzx81/parsebox) project.
1176
1176
 
1177
1177
  <a name='values'></a>
1178
1178
 
@@ -1333,7 +1333,7 @@ const R = Value.Parse(Type.String(), 'hello') // const R: string = "hello"
1333
1333
  const E = Value.Parse(Type.String(), undefined) // throws AssertError
1334
1334
  ```
1335
1335
 
1336
- You can override the order in which functions are are run, or omit functions entirely in the following way.
1336
+ You can override the order in which functions are run, or omit functions entirely using the following.
1337
1337
 
1338
1338
  ```typescript
1339
1339
  // Runs no functions.