Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sinclairzx81 committed Nov 16, 2024
1 parent e1dc6fa commit 7e36540
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 37 deletions.
74 changes: 42 additions & 32 deletions example/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,48 @@ import { TypeSystem } from '@sinclair/typebox/system'
import { TypeCompiler } from '@sinclair/typebox/compiler'
import { Value, ValuePointer } from '@sinclair/typebox/value'
import { Parse, StaticParseAsType } from '@sinclair/typebox/syntax'
import { Type, Index, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox'

// Computed Types:
// - Awaited (Computed)
// - Partial (Computed)
// - Pick (Computed)
// - Omit (Computed)
// - Required (Computed)
// - KeyOf (Computed)
// - Index (Computed ... mostly (needs rewrite))
// - Record (Computed)

// const Module = Parse(`module {

// type A = {
// x: number
// y: number
// z: number
// }

// type K = A[keyof A]

// }`)

const Module = Type.Module({
T: Type.Record(Type.TemplateLiteral('${0|1}${0|1}${0|1}'), Type.String()),
// T: Type.Object({
// x: Type.Number(),
// y: Type.Number()
// }),
Z: Type.Partial(Type.Ref('T')),
import { Type, TypeGuard, Kind, Static, TSchema } from '@sinclair/typebox'

// -----------------------------------------------------------
// Create: Type
// -----------------------------------------------------------

const T = Type.Object({
x: Type.Number(),
y: Type.Number(),
z: Type.Number(),
})

const T = Module.Import('Z')
type T = Static<typeof T>

console.log(T)

// -----------------------------------------------------------
// Parse: Type
// -----------------------------------------------------------

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

type S = Static<typeof S>

// -----------------------------------------------------------
// Create: Value
// -----------------------------------------------------------

const V = Value.Create(T)

console.log(V)

// -----------------------------------------------------------
// Compile: Type
// -----------------------------------------------------------

const C = TypeCompiler.Compile(T)

console.log(C.Code())

// -----------------------------------------------------------
// Check: Value
// -----------------------------------------------------------

console.log(C.Check(V))
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -1886,12 +1886,12 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
┌──────────────────────┬────────────┬────────────┬─────────────┐
│ (index) │ CompiledMinifiedCompression
├──────────────────────┼────────────┼────────────┼─────────────┤
typebox/compiler'121.7 kb'' 53.4 kb''2.28 x'
typebox/errors' 75.3 kb'' 33.4 kb''2.25 x'
typebox/syntax'120.1 kb'' 50.5 kb''2.38 x'
typebox/compiler'122.4 kb'' 53.4 kb''2.29 x'
typebox/errors' 67.6 kb'' 29.6 kb''2.28 x'
typebox/syntax'132.9 kb'' 54.2 kb''2.45 x'
typebox/system' 7.4 kb'' 3.2 kb''2.33 x'
typebox/value'160.3 kb'' 67.4 kb''2.38 x'
typebox' 96.2 kb'' 40.2 kb''2.39 x'
typebox/value'150.1 kb'' 62.2 kb''2.41 x'
typebox'106.8 kb'' 43.2 kb''2.47 x'
└──────────────────────┴────────────┴────────────┴─────────────┘
```
Expand Down

0 comments on commit 7e36540

Please sign in to comment.