Skip to content

Commit 4cffe1e

Browse files
committed
Documentation
1 parent 3999862 commit 4cffe1e

5 files changed

Lines changed: 94 additions & 33 deletions

File tree

deno.jsonc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"strict": true,
6363
"jsx": "react-jsx",
6464
"jsxImportSource": "npm:react@19.1.1",
65+
"types": ["npm:@types/react", "npm:@types/react-dom", "npm:@types/three"],
6566
"lib": ["deno.ns", "dom"]
6667
}
6768
}

deno.lock

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

design/website/docs/script/overview.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ A TypeScript Engine for JavaScript
44

55
## Overview
66

7-
TypeBox is a runtime type system that uses Json Schema as an AST for runtime type representation. The Script function provides a syntactic frontend to the type system and allows Json Schema to be created using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.
7+
TypeBox is a type system designed to use Json Schema as an AST for runtime type representation. The Script function provides a full syntactic frontend to the type system and enables Json Schema to be constructed using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.
88

99
### Example
1010

11-
The following uses the Script function to create and transform Json Schema types.
11+
The following uses Script to construct and map Json Schema.
1212

1313
```typescript
14-
import Type from 'typebox'
14+
import Type, { type Static } from 'typebox'
1515

1616
const T = Type.Script(`{
1717
x: number,
@@ -27,15 +27,32 @@ const T = Type.Script(`{
2727
// }
2828
// }
2929

30-
// Mapped Type
31-
3230
const S = Type.Script({ T }, `{
3331
[K in keyof T]: T[K] | null
34-
}`) // const S: TObject<{
35-
// x: TUnion<[TNumber, TNull]>,
36-
// y: TUnion<[TNumber, TNull]>,
37-
// z: TUnion<[TNumber, TNull]>
38-
// }>
32+
}`) // const S = {
33+
// type: 'object',
34+
// required: ['x', 'y', 'z'],
35+
// properties: {
36+
// x: {
37+
// anyOf: [
38+
// { type: 'number' },
39+
// { type: 'null' }
40+
// ]
41+
// },
42+
// y: {
43+
// anyOf: [
44+
// { type: 'number' },
45+
// { type: 'null' }
46+
// ]
47+
// },
48+
// z: {
49+
// anyOf: [
50+
// { type: 'number' },
51+
// { type: 'null' }
52+
// ]
53+
// },
54+
// }
55+
// }
3956

4057
type S = Static<typeof S> // type S = {
4158
// x: number | null,

docs/docs/script/overview.html

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<h1>Script</h1>
22
<p>A TypeScript Engine for JavaScript</p>
33
<h2>Overview</h2>
4-
<p>TypeBox is a runtime type system that uses Json Schema as an AST for runtime type representation. The Script function provides a syntactic frontend to the type system and allows Json Schema to be created using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.</p>
4+
<p>TypeBox is a type system designed to use Json Schema as an AST for runtime type representation. The Script function provides a full syntactic frontend to the type system and enables Json Schema to be constructed using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.</p>
55
<h3>Example</h3>
6-
<p>The following uses the Script function to create and transform Json Schema types.</p>
7-
<pre><code class="language-typescript">import Type from &#39;typebox&#39;
6+
<p>The following uses Script to construct and map Json Schema.</p>
7+
<pre><code class="language-typescript">import Type, { type Static } from &#39;typebox&#39;
88

99
const T = Type.Script(`{
1010
x: number,
@@ -20,15 +20,32 @@ <h3>Example</h3>
2020
// }
2121
// }
2222

23-
// Mapped Type
24-
2523
const S = Type.Script({ T }, `{
2624
[K in keyof T]: T[K] | null
27-
}`) // const S: TObject&lt;{
28-
// x: TUnion&lt;[TNumber, TNull]&gt;,
29-
// y: TUnion&lt;[TNumber, TNull]&gt;,
30-
// z: TUnion&lt;[TNumber, TNull]&gt;
31-
// }&gt;
25+
}`) // const S = {
26+
// type: &#39;object&#39;,
27+
// required: [&#39;x&#39;, &#39;y&#39;, &#39;z&#39;],
28+
// properties: {
29+
// x: {
30+
// anyOf: [
31+
// { type: &#39;number&#39; },
32+
// { type: &#39;null&#39; }
33+
// ]
34+
// },
35+
// y: {
36+
// anyOf: [
37+
// { type: &#39;number&#39; },
38+
// { type: &#39;null&#39; }
39+
// ]
40+
// },
41+
// z: {
42+
// anyOf: [
43+
// { type: &#39;number&#39; },
44+
// { type: &#39;null&#39; }
45+
// ]
46+
// },
47+
// }
48+
// }
3249

3350
type S = Static&lt;typeof S&gt; // type S = {
3451
// x: number | null,

readme.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ type T = Static<typeof T> // type T = {
110110
111111
## Script
112112
113-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAFQJ5gKYBo4G84xauAZRgEMZgBjOAXzgDMoIQ4ByPNAIwgA8WAoPhQgA7AM7wEcALyJ8AOkIUowMDAAUAAxx84cbgC44wgK4gOqKJh1wkhk2YtXdALzunzUOH2oaAlLoDAoOCQ0LCggHoIuCExCWlEAHkOACtUChgAHixrcLz8gsCogINEADl3R1zCmtqi6N1bcsrLarr2guKXQwQKhyg2jqHQ4uoAPgFY8SIE5DQFJRV1HElqTC1rAG0AaThgYTgAa1QkCDpEAF0enYu4AB8jYwAbJ+8-YY-g4qn4Qh7ktIZbKDT6fLp6HoAVWEwBEmU2vRamERLwuY3QINBw3BTQQ0NhwnhiP6yIqqPRmKxHXBrkQ+LhCL6HlJzyeaMpVLqowmfHYBEICWIZEomT5ZyIY05xT5MxkOU5WPBpXsHnujxeGIVoJxbn6apMGo5Ws6DTgtJVFn1rKNxryowEfCAA)
113+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example](https://www.typescriptlang.org/play/?moduleResolution=99&target=99&jsx=0&module=199#code/JYWwDg9gTgLgBAFQJ5gKYBo4G84xauAZRgEMZgBjOAXzgDMoIQ4ByPNAIwgA8WAoPhQgA7AM7wEcALyJ8AOkIUowMDAAUAAxx84cbgC44wgK4gOqKJh1wkhk2YtXdALzunzUOH2oaAlLoDAoOCQ0LCggHoIuCExCWlsa3DklNTAqID2VEMWCA4AK1QKGBZ0JLSKyvTo3ShUAEdjYDqAE0MAbRZeTBYkUtZnFgBdMqqxqozdMEY0WGBUUUMscvHVsMmAg2xcfBz7DxYaUbWT0I3dW22svfcLQ+pj06eA87hXK93WfbuaFeeTjbUP7-VYZIGCETiIgJZBoBRKFTqHCSB5wLTWdoAaTgwGEcAA1qgkBA6IghoYEFihnAAD5GYwAGwZ3j8IIB0ViUMICWWbKeG2urDyhWKpWBfMqGzqjWaqDacE63VYfR6gxG4olaQ20wgs3ICyWGs1KVeW20xtBNSCJGESAA8nQOkaLesrcEcIKWN8oPcnC6Jm6gh7Pl7GQz7s7-cFXrpqZGo9Ugg94wndK9LubU6kY3AbfbHQqU6mc7pg2gbg4fUcvFns4HAmXsl8wxHayb63A423kq9k93wq93pn+yEc3mHU6R2cO6WduXm5XfTWp9GZx956Gma2V5EO12d4nAn2Dy8rUCT6ffnwstCZMQyJQADxZElEAB8IIyN+5Ml5F7gGxbN6tL0kyjwnhslzAXSJhgUWCYbO80Ggcy-4AdE1BAA)
114114
115-
TypeBox is a runtime type system that uses Json Schema as an AST for runtime type representation. The Script function provides a syntactic frontend to the type system and allows Json Schema to be created using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.
115+
TypeBox is a type system designed to use Json Schema as an AST for runtime type representation. The Script function provides a full syntactic frontend to the type system and enables Json Schema to be constructed using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.
116116
117117
### Example
118118
119-
The following uses Script to create and map types.
119+
The following uses Script to construct and map Json Schema.
120120
121121
```typescript
122122
import Type, { type Static } from 'typebox'
@@ -125,19 +125,42 @@ const T = Type.Script(`{
125125
x: number,
126126
y: number,
127127
z: number
128-
}`) // const T = TObject<{
129-
// x: TNumber,
130-
// y: TNumber,
131-
// z: TNumber
132-
// }>
128+
}`) // const T = {
129+
// type: 'object',
130+
// required: ['x', 'y', 'z'],
131+
// properties: {
132+
// x: { type: 'number' },
133+
// y: { type: 'number' },
134+
// z: { type: 'number' }
135+
// }
136+
// }
133137

134138
const S = Type.Script({ T }, `{
135139
[K in keyof T]: T[K] | null
136-
}`) // const S: TObject<{
137-
// x: TUnion<[TNumber, TNull]>,
138-
// y: TUnion<[TNumber, TNull]>,
139-
// z: TUnion<[TNumber, TNull]>
140-
// }>
140+
}`) // const S = {
141+
// type: 'object',
142+
// required: ['x', 'y', 'z'],
143+
// properties: {
144+
// x: {
145+
// anyOf: [
146+
// { type: 'number' },
147+
// { type: 'null' }
148+
// ]
149+
// },
150+
// y: {
151+
// anyOf: [
152+
// { type: 'number' },
153+
// { type: 'null' }
154+
// ]
155+
// },
156+
// z: {
157+
// anyOf: [
158+
// { type: 'number' },
159+
// { type: 'null' }
160+
// ]
161+
// },
162+
// }
163+
// }
141164

142165
type S = Static<typeof S> // type S = {
143166
// x: number | null,

0 commit comments

Comments
 (0)