# 1.3.0


---

### Version Updates
- [Revision 1.3.11](https://github.com/sinclairzx81/typebox/pull/1664)
  - Clone and Discard Memory Optimization
- [Revision 1.3.10](https://github.com/sinclairzx81/typebox/pull/1662)
  - MaxInstantiationCount System Configuration
  - Ensure Enum and TemplateLiteral Types are Distributed as Generic Arguments
- [Revision 1.3.9](https://github.com/sinclairzx81/typebox/pull/1660)
  - Optimize Tuple and Delimited Sequence Parsing
- [Revision 1.3.8](https://github.com/sinclairzx81/typebox/pull/1656)
  - [1655](https://github.com/sinclairzx81/typebox/pull/1655) Index Tracking for Contains Keyword
  - Index Tracking for MinContains Keyword
  - Use Simplified Ordinals for Generated Function Names
- [Revision 1.3.7](https://github.com/sinclairzx81/typebox/pull/1654)
  - [1652](https://github.com/sinclairzx81/typebox/pull/1652) Compiler Guard for Multi-Variant Types
  - [1645](https://github.com/sinclairzx81/typebox/pull/1645) Documentation
- [Revision 1.3.6](https://github.com/sinclairzx81/typebox/pull/1648)
  - Fix: Fast-Path Length Guards Miss Variation Selectors and Extended Combining Marks
- [Revision 1.3.5](https://github.com/sinclairzx81/typebox/pull/1647)
  - Restore ReadonlyType Alias
- [Revision 1.3.4](https://github.com/sinclairzx81/typebox/pull/1644)
  - Use SchemaRef + Href Registry for Improved Compiler Performance
- [Revision 1.3.3](https://github.com/sinclairzx81/typebox/pull/1642)
  - IsMultipleOf Accepts Negative Fractional Multiples
- [Revision 1.3.2](https://github.com/sinclairzx81/typebox/pull/1640)
  - Repair uses Default when Value is Undefined
- [Revision 1.3.1](https://github.com/sinclairzx81/typebox/pull/1638)
  - Unsafe Keyword Uses Property Enumeration Rules on Clone

---

<a name="Overview"></a>

## Overview

Revision 1.3.0 is a maintenance revision that removes several deprecated types and stabilizes the 1.x feature set in preparation for Value.* updates planned later in the year. This revision also finalizes preparation for the TypeScript 7 native compiler release, in which all TypeBox inference paths are trimmed down to their core essentials to ensure the best possible inference performance for `Type.Script`.

Despite these deprecations, this revision is expected to be very low impact. A major version bump has been deferred until the aforementioned Value.* work has been finalized. The planned Value.* updates are expected to include breaking API changes to Encode and Decode along with some potential changes to StaticEncode, StaticDecode. 

TypeBox will defer 2.x until Value.* functions are finalized.

# Contents

- [Overview](#Overview)
- [Deprecations](#Deprecations)
  - [Base](#Base)
  - [Awaited, Promise, AsyncIterator, and Iterator](#Awaited-Promise-AsyncIterator-and-Iterator)
  - [Mutate](#Mutate)
- [Bundle](#Bundle)

---

<a name="Deprecations"></a>

## Deprecations

The following types and functions are being deprecated.

- Type
  - Base
  - Awaited
  - Promise
  - AsyncIterator
  - Iterator
- Value
  - Mutate

<a name="Base"></a>

## Base

The Base type was originally added in the 1.x release to be used as a hook to try and support Standard Schema. However early into the 1.x release, it became clear that supporting class instances embedded in JSON Schema was going to be untenable in the longer term, both from a type-mapping standpoint and from a runtime type computation standpoint, particularly when handling structured clones of user-defined JavaScript Base class instances.

TypeBox has discontinued support for Standard Schema since 1.0.28, both because of the complexity cost of hosting the specification within JSON Schema was too high, and because the specification conflicts with the standardization efforts TypeBox follows, specifically JSON Schema under IETF and ECMA.

TypeBox will reject class instances embedded in schematics moving forward as a core design constraint, however an external reference adapter to Standard Schema can be found at the link below.

[Reference: Standard Schema](https://github.com/sinclairzx81/typebox/tree/main/example/standard)

### Use Unsafe / Refine Instead of Base

As the Base type was also servicing as an extension mechanism for user defined types in early 1.0.x, implementations should update to use Unsafe / Refine moving forward. The previous Base fallbacks for Uint8Array and Date have been updated to use the Unsafe / Refine pairing at the links below.

- [Reference: Uint8Array](https://github.com/sinclairzx81/typebox/blob/main/example/legacy/uint8array.ts)
- [Reference: Date](https://github.com/sinclairzx81/typebox/blob/main/example/legacy/date.ts)

A reference implementation for Uint8Array is as follows:

```typescript
import Type from 'typebox'

export type TUint8Array = Type.TUnsafe<globalThis.Uint8Array>

export function Uint8Array(): TUint8Array {
  return Type.Refine(Type.Unsafe<globalThis.Uint8Array>({ type: 'Uint8Array' }), 
    value => value instanceof globalThis.Uint8Array,
    _value => 'Expected Uint8Array')
}
```

<a name="Awaited-Promise-AsyncIterator-and-Iterator"></a>

## Awaited, Promise, AsyncIterator, and Iterator

Revision 1.3.x removes these types in favor of structural composition via TypeBox's existing type system. Moving forward, TypeBox will consider all JavaScript built-ins to be higher-order constructs that can be composed from simpler types. TypeScript models JavaScript built-ins in the exact same way.

These specific types date back to earlier versions of 0.x, where they were originally added to model RPC function return types. The intention was to describe callable RPC interfaces; however, a consumer of an RPC service rarely needs to know if a RPC server function is synchronous or asynchronous (it's always asynchronous from the callers perspective), and where other aspects such as iteration and streaming is best described against the capabilities of the RPC protocol, not TypeBox's definition of a JavaScript iterator.

To highlight composition, the following example models `lib.d.ts`-style definitions for `Promise` and `Date` using TypeBox's existing primitives, then uses the resulting `Promise` type to describe an RPC-style function. The aspect to consider here is that `Promise<T>` can be modelled through structural composition, which is much better than TypeBox carrying around intrinsic definitions for these types.

```typescript
// -----------------------------------------------------------
// Model various lib.d.ts definitions
// -----------------------------------------------------------
const lib_d_ts = Type.Script(`
  type Promise<T = unknown> = {
    then: (onFulfilled: (value: T) => unknown) => unknown;
  }

  type Date = {
    getTime: () => number
    getDate: () => number
    getTime: () => number
    getFullYear: () => number // etc, etc
  }
`)

// -----------------------------------------------------------
// Application Types
// -----------------------------------------------------------
const { Add } = Type.Script(lib_d_ts, `

  type Vector = { x: number, y: number }

  type Add = (a: Vector, b: Vector) => Promise<Vector> // from lib.d.ts
`)

// Example
declare const add: Type.Static<typeof Add>

const { x, y } = await add(      // { x: number, y: number }
  { x: 1, y: 0 }, 
  { x: 0, y: 1 }
) 
```

The `Function` and `Constructor` types will remain as part of TypeBox's Type IR extensions to JSON Schema.

<a name="Mutate"></a>

## Mutate

The Mutate type was introduced in 0.27.x to handle updates to React state without triggering a redraw. The function was written for that specific use case, and its scope is generally too narrow for inclusion in TypeBox; a utility like this is better suited to React itself.

A fallback implementation is being retained under `example/mutate/*`, which can be copied into projects that still require it; however, its usage across the ecosystem is believed to be minimal to nonexistent.

<a name="Bundle"></a>

## Bundle

The following are the bundle metrics for 1.2.x and 1.3.x with the deprecations applied.

### 1.2.x
```bash
┌───────┬───────────────────────────────────────────┬─────────────┬─────────────┬────────────┐
│ (idx) │ path                                      │ bundled     │ minified    │ gzipped    │
├───────┼───────────────────────────────────────────┼─────────────┼─────────────┼────────────┤
│     0 │ "task/metrics/all.ts"                     │ "463.59 KB" │ "181.77 KB" │ "45.92 KB" │
│     1 │ "task/metrics/compile_all.ts"             │ "341.40 KB" │ "129.26 KB" │ "34.36 KB" │
│     2 │ "task/metrics/schema_all.ts"              │ "173.79 KB" │ "75.06 KB"  │ "19.13 KB" │
│     3 │ "task/metrics/schema_check.ts"            │ "79.74 KB"  │ "33.97 KB"  │ "10.36 KB" │
│     4 │ "task/metrics/schema_compile.ts"          │ "154.02 KB" │ "65.10 KB"  │ "17.74 KB" │
│     5 │ "task/metrics/schema_errors.ts"           │ "109.82 KB" │ "46.63 KB"  │ "13.15 KB" │
│     6 │ "task/metrics/schema_parse.ts"            │ "110.80 KB" │ "46.96 KB"  │ "13.27 KB" │
│     7 │ "task/metrics/type_all.ts"                │ "225.25 KB" │ "83.34 KB"  │ "21.45 KB" │
│     8 │ "task/metrics/type_barrel.ts"             │ "16.44 KB"  │ "7.21 KB"   │ "2.79 KB"  │
│     9 │ "task/metrics/type_builder.ts"            │ "211.93 KB" │ "76.66 KB"  │ "19.64 KB" │
│    10 │ "task/metrics/type_default.ts"            │ "211.97 KB" │ "76.67 KB"  │ "19.64 KB" │
│    11 │ "task/metrics/type_realistic_dynamic.ts"  │ "117.40 KB" │ "49.73 KB"  │ "14.23 KB" │
│    12 │ "task/metrics/type_realistic_compiled.ts" │ "160.63 KB" │ "67.90 KB"  │ "18.71 KB" │
│    13 │ "task/metrics/type_script.ts"             │ "199.23 KB" │ "71.14 KB"  │ "18.00 KB" │
│    14 │ "task/metrics/value_all.ts"               │ "309.70 KB" │ "116.09 KB" │ "31.38 KB" │
│    15 │ "task/metrics/value_check.ts"             │ "281.11 KB" │ "105.12 KB" │ "28.11 KB" │
│    16 │ "task/metrics/value_clean.ts"             │ "281.11 KB" │ "105.12 KB" │ "28.11 KB" │
│    17 │ "task/metrics/value_clone.ts"             │ "281.11 KB" │ "105.12 KB" │ "28.11 KB" │
│    18 │ "task/metrics/value_convert.ts"           │ "281.11 KB" │ "105.12 KB" │ "28.11 KB" │
│    19 │ "task/metrics/value_create.ts"            │ "288.63 KB" │ "107.77 KB" │ "28.92 KB" │
│    20 │ "task/metrics/value_hash.ts"              │ "281.20 KB" │ "105.16 KB" │ "28.13 KB" │
│    21 │ "task/metrics/value_mutate.ts"            │ "283.93 KB" │ "106.21 KB" │ "28.51 KB" │
│    22 │ "task/metrics/value_pointer.ts"           │ "281.12 KB" │ "105.12 KB" │ "28.11 KB" │
│    23 │ "task/metrics/value_repair.ts"            │ "298.20 KB" │ "111.23 KB" │ "29.91 KB" │
└───────┴───────────────────────────────────────────┴─────────────┴─────────────┴────────────┘
```
### 1.3.x
```bash
┌───────┬───────────────────────────────────────────┬─────────────┬─────────────┬────────────┐
│ (idx) │ path                                      │ bundled     │ minified    │ gzipped    │
├───────┼───────────────────────────────────────────┼─────────────┼─────────────┼────────────┤
│     0 │ "task/metrics/all.ts"                     │ "448.40 KB" │ "175.77 KB" │ "44.32 KB" │
│     1 │ "task/metrics/compile_all.ts"             │ "331.35 KB" │ "125.40 KB" │ "33.43 KB" │
│     2 │ "task/metrics/schema_bench.ts"            │ "118.89 KB" │ "50.42 KB"  │ "14.48 KB" │
│     3 │ "task/metrics/schema_all.ts"              │ "171.33 KB" │ "73.82 KB"  │ "18.90 KB" │
│     4 │ "task/metrics/schema_check.ts"            │ "78.71 KB"  │ "33.47 KB"  │ "10.25 KB" │
│     5 │ "task/metrics/schema_compile.ts"          │ "151.90 KB" │ "64.05 KB"  │ "17.52 KB" │
│     6 │ "task/metrics/schema_errors.ts"           │ "108.36 KB" │ "45.91 KB"  │ "13.01 KB" │
│     7 │ "task/metrics/schema_parse.ts"            │ "109.34 KB" │ "46.23 KB"  │ "13.10 KB" │
│     8 │ "task/metrics/type_all.ts"                │ "221.50 KB" │ "82.22 KB"  │ "21.14 KB" │
│     9 │ "task/metrics/type_barrel.ts"             │ "19.37 KB"  │ "8.84 KB"   │ "3.13 KB"  │
│    10 │ "task/metrics/type_builder.ts"            │ "208.82 KB" │ "75.89 KB"  │ "19.36 KB" │
│    11 │ "task/metrics/type_default.ts"            │ "208.86 KB" │ "75.90 KB"  │ "19.39 KB" │
│    12 │ "task/metrics/type_realistic_dynamic.ts"  │ "116.79 KB" │ "49.38 KB"  │ "14.20 KB" │
│    13 │ "task/metrics/type_realistic_compiled.ts" │ "159.37 KB" │ "67.23 KB"  │ "18.61 KB" │
│    14 │ "task/metrics/type_script.ts"             │ "198.02 KB" │ "71.14 KB"  │ "18.01 KB" │
│    15 │ "task/metrics/value_all.ts"               │ "299.34 KB" │ "112.11 KB" │ "30.38 KB" │
│    16 │ "task/metrics/value_check.ts"             │ "274.71 KB" │ "102.57 KB" │ "27.61 KB" │
│    17 │ "task/metrics/value_clean.ts"             │ "274.71 KB" │ "102.57 KB" │ "27.61 KB" │
│    18 │ "task/metrics/value_clone.ts"             │ "274.71 KB" │ "102.57 KB" │ "27.61 KB" │
│    19 │ "task/metrics/value_convert.ts"           │ "274.71 KB" │ "102.57 KB" │ "27.61 KB" │
│    20 │ "task/metrics/value_create.ts"            │ "281.47 KB" │ "104.98 KB" │ "28.34 KB" │
│    21 │ "task/metrics/value_hash.ts"              │ "274.80 KB" │ "102.60 KB" │ "27.64 KB" │
│    22 │ "task/metrics/value_pointer.ts"           │ "274.72 KB" │ "102.57 KB" │ "27.61 KB" │
│    23 │ "task/metrics/value_repair.ts"            │ "290.71 KB" │ "108.34 KB" │ "29.29 KB" │
└───────┴───────────────────────────────────────────┴─────────────┴─────────────┴────────────┘
```