Decompose monolithic readme into docs/ directory structure
This commit is contained in:
101
docs/types/javascript.md
Normal file
101
docs/types/javascript.md
Normal file
@@ -0,0 +1,101 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | **Types** | [Values](../values/) | [Syntax](../syntax/) | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# JavaScript Types
|
||||
|
||||
TypeBox provides an extended type set that can be used to create schematics for common JavaScript constructs. These types can not be used with any standard Json Schema validator; but can be used to frame schematics for interfaces that may receive Json validated data. JavaScript types are prefixed with the `[JavaScript]` JSDoc comment for convenience. The following table lists the supported types.
|
||||
|
||||
```typescript
|
||||
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
||||
│ TypeBox │ TypeScript │ Extended Schema │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Constructor([ │ type T = new ( │ const T = { │
|
||||
│ Type.String(), │ arg0: string, │ type: 'Constructor', │
|
||||
│ Type.Number() │ arg0: number │ parameters: [{ │
|
||||
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
||||
│ │ │ }, { │
|
||||
│ │ │ type: 'number' │
|
||||
│ │ │ }], │
|
||||
│ │ │ returns: { │
|
||||
│ │ │ type: 'boolean' │
|
||||
│ │ │ } │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Function([ │ type T = ( │ const T = { │
|
||||
| Type.String(), │ arg0: string, │ type: 'Function', │
|
||||
│ Type.Number() │ arg1: number │ parameters: [{ │
|
||||
│ ], Type.Boolean()) │ ) => boolean │ type: 'string' │
|
||||
│ │ │ }, { │
|
||||
│ │ │ type: 'number' │
|
||||
│ │ │ }], │
|
||||
│ │ │ returns: { │
|
||||
│ │ │ type: 'boolean' │
|
||||
│ │ │ } │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Promise( │ type T = Promise<string> │ const T = { │
|
||||
│ Type.String() │ │ type: 'Promise', │
|
||||
│ ) │ │ item: { │
|
||||
│ │ │ type: 'string' │
|
||||
│ │ │ } │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = │ type T = │ const T = { │
|
||||
│ Type.AsyncIterator( │ AsyncIterableIterator< │ type: 'AsyncIterator', │
|
||||
│ Type.String() │ string │ items: { │
|
||||
│ ) │ > │ type: 'string' │
|
||||
│ │ │ } │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Iterator( │ type T = │ const T = { │
|
||||
│ Type.String() │ IterableIterator<string> │ type: 'Iterator', │
|
||||
│ ) │ │ items: { │
|
||||
│ │ │ type: 'string' │
|
||||
│ │ │ } │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.RegExp(/abc/i) │ type T = string │ const T = { │
|
||||
│ │ │ type: 'RegExp' │
|
||||
│ │ │ source: 'abc' │
|
||||
│ │ │ flags: 'i' │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Uint8Array() │ type T = Uint8Array │ const T = { │
|
||||
│ │ │ type: 'Uint8Array' │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Date() │ type T = Date │ const T = { │
|
||||
│ │ │ type: 'Date' │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Undefined() │ type T = undefined │ const T = { │
|
||||
│ │ │ type: 'undefined' │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Symbol() │ type T = symbol │ const T = { │
|
||||
│ │ │ type: 'symbol' │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.BigInt() │ type T = bigint │ const T = { │
|
||||
│ │ │ type: 'bigint' │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
||||
│ const T = Type.Void() │ type T = void │ const T = { │
|
||||
│ │ │ type: 'void' │
|
||||
│ │ │ } │
|
||||
│ │ │ │
|
||||
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
Reference in New Issue
Block a user