### 0.34.0

---

### Revision Updates
- [Revision 0.34.43](https://github.com/sinclairzx81/typebox-legacy/pull/1)
  - Configure Package Homepage to refer to TypeBox Legacy Repository.
- [Revision 0.34.42](https://github.com/sinclairzx81/typebox-legacy)
  - Enable Forward Type Inference Compatibility with TypeBox V1
- [Revision 0.34.41](https://github.com/sinclairzx81/typebox/pull/1310)
  - Disable Node10 Module Resolution | TS7 Deprecation Warning.
- [Revision 0.34.40](https://github.com/sinclairzx81/typebox/pull/1293)
  - Use Uniform over Reciprocal weighting on Cast Union Select
- [Revision 0.34.39](https://github.com/sinclairzx81/typebox/pull/1296)
  - Guard for Array in Object and Record conversion
- [Revision 0.34.38](https://github.com/sinclairzx81/typebox/pull/1282)
  - Preserve exact type matches in Union conversion
- [Revision 0.34.37](https://github.com/sinclairzx81/typebox/pull/1278)
  - Fix Support nested Union selection when scoring for Cast
- [Revision 0.34.36](https://github.com/sinclairzx81/typebox/pull/1276)
  - Fix Record Intersect on Cast
- [Revision 0.34.35](https://github.com/sinclairzx81/typebox/pull/1265)
  - Deep Assign on Intersect Cast
- [Revision 0.34.34](https://github.com/sinclairzx81/typebox/pull/1263)
  - Support Inference of Ref inside Recursive inside Module
- [Revision 0.34.33](https://github.com/sinclairzx81/typebox/pull/1220)
  - Hotfix: Correct Invalid Import Specifier
- [Revision 0.34.32](https://github.com/sinclairzx81/typebox/pull/1218)
  - Accelerated | High Performance Syntax Parsing
- [Revision 0.34.31](https://github.com/sinclairzx81/typebox/pull/1209)
  - Use Tail Call Optimized Inference for Records with Large Union Keys
- [Revision 0.34.30](https://github.com/sinclairzx81/typebox/pull/1198)
  - Additional Syntax Parsing Optimizations
- [Revision 0.34.29](https://github.com/sinclairzx81/typebox/pull/1197)
  - Syntax Parsing Optimizations
- [Revision 0.34.28](https://github.com/sinclairzx81/typebox/pull/1187)
  - Add Cast to Configurable Parse Pipeline
- [Revision 0.34.27](https://github.com/sinclairzx81/typebox/pull/1182)
  - [1178](https://github.com/sinclairzx81/typebox/issues/1178) Support Deep Referential Transform Inference Inside Modules
- [Revision 0.34.26](https://github.com/sinclairzx81/typebox/pull/1181)
  - Internal: Use Parser Context Threading for Generic Arguments.
- [Revision 0.34.25](https://github.com/sinclairzx81/typebox/pull/1176)
  - Evaluate Conditional Expression for Instatiated Object Types
- [Revision 0.34.24](https://github.com/sinclairzx81/typebox/pull/1175)
  - Add Support For Generic Parameter Syntax
- [Revision 0.34.23](https://github.com/sinclairzx81/typebox/pull/1174)
  - Inline Instantiate Type Logic Local to Instantiate Module
- [Revision 0.34.22](https://github.com/sinclairzx81/typebox/pull/1171)
  - Intrinsic Types Number, String, Boolean, etc Passthrough on Required and Partial Mapping
- [Revision 0.34.21](https://github.com/sinclairzx81/typebox/pull/1168)
  - Reimplement Computed Record Types
- [Revision 0.34.20](https://github.com/sinclairzx81/typebox/pull/1167)
  - Hotfix: Disable Computed Record Types
- [Revision 0.34.19](https://github.com/sinclairzx81/typebox/pull/1166)
  - Hotfix: Republished due to NPM error
- [Revision 0.34.18](https://github.com/sinclairzx81/typebox/pull/1164)
  - Hotfix: Internal Remap Imports
- [Revision 0.34.17](https://github.com/sinclairzx81/typebox/pull/1162)
  - Add Argument() and Instantiate() Types and Instancing via Syntax support.
- [Revision 0.34.16](https://github.com/sinclairzx81/typebox/pull/1156)
  - Export TypeBox String Parsing Infrastructure
- [Revision 0.34.15](https://github.com/sinclairzx81/typebox/pull/1148)
  - [1147](https://github.com/sinclairzx81/typebox/issues/1147) Fix incorrect truncation for integers that exceed 32-bit values in Value.Convert
- [Revision 0.34.14](https://github.com/sinclairzx81/typebox/pull/1140)
  - [1139](https://github.com/sinclairzx81/typebox/issues/1139) Update TypeCompiler Check for Promise (use instanceof Promise over Thenable check)
- [Revision 0.34.13](https://github.com/sinclairzx81/typebox/pull/1124)
  - Pre emptive fix for TypeScript 5.8.0-nightly to resolve symbol narrowing on Convert.
- [Revision 0.34.12](https://github.com/sinclairzx81/typebox/pull/1120)
  - [1119](https://github.com/sinclairzx81/typebox/issues/1119) Fix for Mutate Object Comparison
  - [1117](https://github.com/sinclairzx81/typebox/issues/1117) Re-Add Type.Recursive Documentation
- [Revision 0.34.11](https://github.com/sinclairzx81/typebox/pull/1110)
  - Fix Compiler Emit for Deeply Referential Module Types
- [Revision 0.34.10](https://github.com/sinclairzx81/typebox/pull/1107)
  - Fix Declaration Emit for Index and Mapped Types
  - Fix Record Inference Presentation when Embedded in Modules
  - Fix Record Mapping when using TImport as Key
  - Add Encode to Parse Operation List
- [Revision 0.34.9](https://github.com/sinclairzx81/typebox/pull/1101)
  - User Defined Parse Pipelines
  - Access to Schema and References on TypeCheck
- [Revision 0.34.8](https://github.com/sinclairzx81/typebox/pull/1098)
  - Fix for Computed Readonly and Optional Properties
- [Revision 0.34.7](https://github.com/sinclairzx81/typebox/pull/1093)
  - Revert Ref(Schema) Signature with Deprecation Notice
- [Revision 0.34.6](https://github.com/sinclairzx81/typebox/pull/1090)
  - Add Computed To Type and Kind Guards (IsSchema)
- [Revision 0.34.5](https://github.com/sinclairzx81/typebox/pull/1088)
  - Record Types no longer TCompute for TRef Value Type (Modules)
- [Revision 0.34.4](https://github.com/sinclairzx81/typebox/pull/1085)
  - Inference Path for Enum within Modules
- [Revision 0.34.3](https://github.com/sinclairzx81/typebox/pull/1083)
  - Retain Array Elements on Value Default
- [Revision 0.34.2](https://github.com/sinclairzx81/typebox/pull/1082)
  - Resolve import pathing issue introduced on 0.34.1
- [Revision 0.34.1](https://github.com/sinclairzx81/typebox/pull/1080)
  - Implement Computed Type Deref in Modules

## [0.34.0](https://www.npmjs.com/package/@sinclair/typebox/v/0.34.0)

## Overview

Revision 0.34.0 represents a significant milestone for the TypeBox project. This update changes how TypeBox manages type references (Ref) and introduces a new Module type to support mutual recursion and self-referencing types. Additionally, it includes a new submodule for parsing TypeScript syntax directly into TypeBox types.

Please note that this release includes breaking changes to Ref and some deprecations. These updates require a minor semver revision.

## Contents

- [Enhancements](#Enhancements)
  - [Module Types](#Module-Types)
  - [Syntax Types](#Syntax-Types)
- [Breaking Changes](#Breaking-Changes)
  - [Ref](#Ref)
  - [Deref](#Deref)
  - [Strict](#Strict)


<a name="Enhancements"></a>

## Enhancements

Below are the enhancements introduced in Version 0.34.0.

<a name="Module-Type"></a>

### Module Types

Revision 0.34.0 introduces a new type, called Module. Modules are represented as JSON Schema $def schematics, specifically designed to support both mutual and self-recursive types. This addition resolves a longstanding issue in TypeBox, where complex recursive structures often encountered "definition order" problems, making certain recursive structures difficult to represent cleanly. With Modules, you can now define schematics within a Module context, allowing them to be referenced within the type system through a separate inference operation.

```typescript
// The following creates a circular recursive type.

const Module = Type.Module({
  A: Type.Object({ 
    b: Type.Ref('B') // Ref B:
  }),
  B: Type.Object({
    c: Type.Ref('C') // Ref C:
  }),
  C: Type.Object({
    a: Type.Ref('A') // Ref A:
  }),
})

// Module types must be imported before use.

const A = Module.Import('A')                     // const A: TImport<{...}, 'A'>

type A = Static<typeof A>                        // type A = { 
                                                 //   b: {
                                                 //     c: {
                                                 //       a: {
                                                 //         b: ...
                                                 //       }
                                                 //     }
                                                 //   }
                                                 // }
```

<a name="Syntax-Types"></a>

### Syntax Types


Revision 0.34.0 introduces a new submodule for parsing TypeScript syntax directly into TypeBox types, implemented both at runtime and within the type system. This feature was made possible through the development of a separate project, [ParseBox](https://github.com/sinclairzx81/parsebox) (MIT-licensed), which provides a symmetric runtime and type-level parsing infrastructure.

As of 0.34.0, Syntax Types are available as an opt-in feature, with the parsing infrastructure adding approximately 10kb (minified) to the existing type builder. With further optimizations, this feature may be elevated to a top-level import in future updates to minimize bundling size.

To use Syntax Types, import them from the `@sinclair/typebox/syntax` path.

```typescript
import { Parse } from '@sinclair/typebox/syntax'

// All primitive types are supported

const A = Parse('string')    // const A: TString
const B = Parse('number')    // const B: TNumber
const C = Parse('boolean')   // const C: TBoolean

// ... Multiline parsing is supported (but comments are not)

const T = Parse(`{
  x: number
  y: number
  z: number
}`)


// ... Parametertized parsing is supported
const O = Parse({ T }, `T & { w: number }`) // const O: TIntersect<[
                                            //   TObject<{
                                            //     x: TNumber,
                                            //     y: TNumber,
                                            //     z: TNumber,
                                            //   }>,
                                            //   TObject<{
                                            //     w: TNumber
                                            //   }>
                                            // ]>

// ... Module parsing is also supported.

const Math = Parse(`module Math {
  export interface X {
    x: number
  }
  export interface Y {
    y: number
  }
  export interface Z {
    z: number
  }
  export interface Vector extends X, Y, Z {
    type: 'Vector'
  }
}`)

const Vector = Math.Import('Vector')     
```

Runtime parsing performance should be quite good; however, static parsing performance could be improved. TypeScript will invoke the parser for each property accessed at design time. Ongoing efforts within the ParseBox project aim to optimize string parsing in TypeScript, with additional research underway into type-level caching strategies within the TypeScript compiler. Additional optimizations will be explored over the course of 0.34.x.

<a name="Breaking-Changes"></a>

## Breaking Changes

The following are the breaking changes in Revision 0.34.0.

<a name="Ref"></a>

### Ref

Revision 0.34.0 introduces a breaking change to Ref, modifying its signature to accept only constant string values. Previously, Ref could accept an existing TypeBox type, provided it had an $id assigned.

```typescript

// Revision 0.33.0

const T = Type.String({ $id: 'T' })

const R = Type.Ref(T)

type R = Static<typeof R>      // type R = string

// Revision 0.34.0

const T = Type.String({ $id: 'T' })

const R = Type.Ref('T')

type R = Static<typeof R>      // type R = unknown

```

In Revision 0.34.0, the inferred type for Ref is now unknown. Implementations using the previous version of Ref can switch to Unsafe to type the reference to the target value.

```typescript
// Revision 0.34.0

const T = Type.String({ $id: 'T' })

const R = Type.Unsafe<Static<typeof T>>(Type.Ref('T'))

type R = Static<typeof R>      // type R = string
```

<a name="Deref"></a>

### Deref

Revision 0.34.0 removes the Deref type, which was previously used to dereference schematics. Since the Ref signature has changed from TSchema to string, there is no longer a way to resolve reference types accurately. TypeBox may provide a prototype example of this type upon request.

<a name="Strict"></a>

### Strict

Revision 0.34.0 removes the Strict type from the Type Builder, which was deprecated in version 0.33.8. This type was introduced several years ago in response to a change in Ajv that prohibited unknown keywords. At that time, TypeBox used string property keys for `kind` and `modifier`, which required either Ajv configuration or the use of Strict. These properties have since been updated to Symbol properties, resolving the issues with Ajv. However, the Strict type remained due to some use in ecosystem projects, which has since reduced.

For those who still need Strict, the recommended approach is to use the JSON stringify/parse method outlined in the deprecation notice.

```typescript
/**
 * @deprecated `[Json]` Omits compositing symbols from this schema. It is recommended
 * to use the JSON parse/stringify to remove compositing symbols if needed. This
 * is how Strict works internally.
 *
 * ```typescript
 * JSON.parse(JSON.stringify(Type.String()))
 * ```
 */
export function Strict<T extends TSchema>(schema: T): TStrict<T> {
  return JSON.parse(JSON.stringify(schema))
}
```