Decompose monolithic readme into docs/ directory structure
This commit is contained in:
29
docs/syntax/create.md
Normal file
29
docs/syntax/create.md
Normal file
@@ -0,0 +1,29 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | [Types](../types/) | [Values](../values/) | **Syntax** | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Create
|
||||
|
||||
TypeBox provides experimental support for parsing TypeScript annotation syntax into TypeBox types.
|
||||
|
||||
This feature is provided via optional import.
|
||||
|
||||
```typescript
|
||||
import { Syntax } from "@alkdev/typebox/syntax";
|
||||
```
|
||||
|
||||
## Create
|
||||
|
||||
Use the Syntax function to create TypeBox types from TypeScript syntax ([Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYBGEHOxoZsOCgChQkWIhTYYwBgWKly1OoxZtO3foMkSGEdDXgAVOAF4Uo3AAoABkhwAuOOgCuIPjygAaOFR3Lx8-AkcASjgY2Jj2djhjUwt3cwB5PgArHgYYAB4ECTiS0rLyisrYhNi3OHMAOW9fAOKq9o7OuBqY4PqmsKg2rpHR+MT8AD4JCS5eeut5LEUGfLmeCCJ6ybHKmvWFmyLdk86euDrQlv9h07uy876rv1v7t-GCIA))
|
||||
|
||||
```typescript
|
||||
const T = Syntax(`{ x: number, y: number }`); // const T: TObject<{
|
||||
// x: TNumber,
|
||||
// y: TNumber
|
||||
// }>
|
||||
|
||||
type T = Static<typeof T>; // type T = {
|
||||
// x: number,
|
||||
// y: number
|
||||
// }
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
30
docs/syntax/generics.md
Normal file
30
docs/syntax/generics.md
Normal file
@@ -0,0 +1,30 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | [Types](../types/) | [Values](../values/) | **Syntax** | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Generics
|
||||
|
||||
Syntax types support generic parameters in the following way ([Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYBGEHOxoZsOCgChQkWIhTYYwBgWKly1OoxZtO3foMkSGEdDXgA1HgxjQ4AXhSjcACgAGAHgAaAGjgBNXwAtAD45CTg4HAAuOB84cLhUGID4iIAvGMD4-FcASgkjEzM4ACEsOhpLa2gae0dMFyQqmygCX1cEBOi4Zuh3AEZfAAZh4O8EpJ6rFvcRuEG4IbGEjKnqqFnh337lnPyJLl5S8uBK6Zq65AUld0OeCCJjit6oGlCIiPZ2ODun05fag5Oh8QaCweCIZCoV8Pt0kN0FpM5qshm0ElCMZisSCYRFJvCYnNJgsUWjseSKeDcXBVgTFr4kb5Vv0COjKezsTD8EA))
|
||||
|
||||
```typescript
|
||||
const Vector = Syntax(`<X, Y, Z> {
|
||||
x: X,
|
||||
y: Y,
|
||||
z: Z
|
||||
}`);
|
||||
|
||||
const BasisVectors = Syntax(
|
||||
{ Vector },
|
||||
`{
|
||||
x: Vector<1, 0, 0>,
|
||||
y: Vector<0, 1, 0>,
|
||||
z: Vector<0, 0, 1>,
|
||||
}`
|
||||
);
|
||||
|
||||
type BasisVectors = Static<typeof BasisVectors>; // type BasisVectors = {
|
||||
// x: { x: 1, y: 0, z: 0 },
|
||||
// y: { x: 0, y: 1, z: 0 },
|
||||
// z: { x: 0, y: 0, z: 1 }
|
||||
// }
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
18
docs/syntax/noinfer.md
Normal file
18
docs/syntax/noinfer.md
Normal file
@@ -0,0 +1,18 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | [Types](../types/) | [Values](../values/) | **Syntax** | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# NoInfer
|
||||
|
||||
Syntax parsing is an expensive type level operation and can impact on language service performance. Use the NoInfer function parse syntax at runtime only.
|
||||
|
||||
```typescript
|
||||
import { NoInfer } from "@alkdev/typebox/syntax";
|
||||
|
||||
const T = NoInfer(`number | string`); // const T: TSchema = {
|
||||
// anyOf: [
|
||||
// { type: 'number' },
|
||||
// { type: 'string' }
|
||||
// ]
|
||||
// }
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
14
docs/syntax/options.md
Normal file
14
docs/syntax/options.md
Normal file
@@ -0,0 +1,14 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | [Types](../types/) | [Values](../values/) | **Syntax** | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Options
|
||||
|
||||
Options can be passed via the last parameter.
|
||||
|
||||
```typescript
|
||||
const T = Syntax(`number`, { minimum: 42 }); // const T = {
|
||||
// type: 'number',
|
||||
// minimum: 42
|
||||
// }
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
19
docs/syntax/parameters.md
Normal file
19
docs/syntax/parameters.md
Normal file
@@ -0,0 +1,19 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | [Types](../types/) | [Values](../values/) | **Syntax** | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Parameters
|
||||
|
||||
Syntax types can be parameterized to receive exterior types ([Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYBGEHOxoZsOCgCgJDCOhrwAKnAC8KUbgAUAAyQ4AXHHQBXEHx5QANHFQHjp8wS0BKOK7ev27ODLmKDCgHk+ACseBhgAHgQJd1i4+ITEpLdPN304BQA5EzNLGOSCwqK4VNcbDOz7KHzi2rqPL3wAPikfeRQVNUxNJCV8Ky0ABSxYYCwmCIUm52LUtvhkfyDQ8Kia+o2C0rh0wLAYYFlxycrcpot1zav47fK9g6OJrJzzFuv3m8amoA))
|
||||
|
||||
```typescript
|
||||
const T = Syntax(`{ x: number, y: number }`); // const T: TObject<{
|
||||
// x: TNumber,
|
||||
// y: TNumber
|
||||
// }>
|
||||
|
||||
const S = Syntax({ T }, `Partial<T>`); // const S: TObject<{
|
||||
// x: TOptional<TNumber>,
|
||||
// y: TOptional<TNumber>
|
||||
// }>
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
Reference in New Issue
Block a user