Skip to content

Commit

Permalink
Prototype Readme | Discard Evaluate and Mutual Prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Oct 3, 2024
1 parent 6580a29 commit 9f06cd8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 217 deletions.
134 changes: 0 additions & 134 deletions example/prototypes/evaluate.ts

This file was deleted.

1 change: 0 additions & 1 deletion example/prototypes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ THE SOFTWARE.
---------------------------------------------------------------------------*/

export * from './evaluate'
export * from './from-schema'
export * from './module'
export * from './partial-deep'
Expand Down
48 changes: 0 additions & 48 deletions example/prototypes/mutual.ts

This file was deleted.

64 changes: 30 additions & 34 deletions example/prototypes/readme.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
# TypeBox Prototypes

TypeBox prototypes are a set of types that are either under consideration for inclusion into the library, or have been requested by users but cannot be added to the library either due to complexity, using schematics that fall outside the supported TypeBox or should be expressed by users via advanced type composition.
TypeBox prototypes are a set of types that are either under consideration for inclusion into the library, or have been requested by users but cannot be added to the library either due to complexity, using schematics that fall outside the supported TypeBox or should be expressed by users via advanced type composition.

Each prototype is written as a standalone module that can be copied into projects and used directly, or integrated into extended type builders.
## Module, ModuleRef and Import

## Const

This type will wrap all interior properties as `readonly` leaving the outer type unwrapped. This type is analogous to the `Readonly<T>` TypeScript utility type, but as TypeBox uses this name as a property modifier, the name `Const` is used.

```typescript
import { Const } from './prototypes'

const T = Const(Type.Object({ // const T: TObject<{
x: Type.Number() // x: Type.Readonly(Type.Number())
})) // }>

type T = Static<typeof T> // type T = {
// readonly x: number
// }
```
## Evaluate
This type is an advanced mapping type will evaluate for schema redundancy by reducing evaluating intersection rest arguments. This type detects if intersection would produce illogical `never`, removes duplicates and handles intersection type narrowing. This type is a strong candidate for inclusion into the TypeBox library but is pending an equivalent redundancy check for `union` rest arguments.
The Module type as a candidate referencing system for TypeBox. Modules enable deferred cross type referencing and support mutual recursive inference. Module types must be instances via `M.Import(...)` which constructs a `$def` schematic containing each definition required to validate, but a self referential `$ref` to the type being imported.

```typescript
import { Evaluate } from './prototypes'
import { Module, ModuleRef } from './prototypes'

// Evaluate for Duplicates
//
const T = Type.Intersect([ Type.Number(), Type.Number(), Type.Number() ])

const E = Evaluate(T) // const E: TNumber
// A module of cross referenced Types. ModuleRef is used to cross reference.
const Math = new Module({
Vector2: Type.Object({
x: Type.Number(),
y: Type.Number(),
}),
Vector3: Type.Object({
x: Type.Number(),
y: Type.Number(),
z: Type.Number()
}),
Vertex: Type.Object({
position: ModuleRef('Vector3'),
normal: ModuleRef('Vector3'),
texcoord: ModuleRef('Vector2')
}),
Geometry: Type.Object({
vertices: Type.Array(ModuleRef('Vertex')),
indices: Type.Array(Type.Integer())
})
})

// Evaluate for TNever
//
const T = Type.Intersect([ Type.Number(), Type.String() ])
// Types must be imported from the Module.
const Vector2 = Math.Import('Vector2')

const E = Evaluate(T) // const E: TIntersect<[TNumber, TString]>
const Vector3 = Math.Import('Vector2')

// Evaluate for most narrowed type
//
const T = Type.Intersect([ Type.Number(), Type.Literal(1) ])
const Vertex = Math.Import('Vertex')

const E = Evaluate(T) // const E: TLiteral<1>
const Geometry = Math.Import('Geometry')
```

## PartialDeep
Expand Down

0 comments on commit 9f06cd8

Please sign in to comment.