You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An experimental TypeBox type builder with additional custom types.
3
+
These examples are a set of experiemental candidate types that may introduced into TypeBox in future.
4
4
5
-
## Overview
5
+
## ReadonlyObject
6
6
7
-
The TypeBox TypeBuilder classes are designed to be extended with user defined types. Instances where you may wish to do this are if your application is dependent on custom schematics and/or non-JSON serializable values (an example of which might be a Mongo's `ObjectId` or other such non-serializable value)
7
+
Maps an object properties as `readonly`.
8
8
9
-
## Application Type Builder
9
+
```typescript
10
+
import { ReadonlyObject } from'./experimental'
11
+
12
+
const T =ReadonlyObject(Type.Object({
13
+
x: Type.Number()
14
+
}))
15
+
16
+
typeT=Static<typeofT> // type T = {
17
+
// readonly x: number
18
+
// }
19
+
```
20
+
## UnionEnum
10
21
11
-
The following shows creating a simple `ApplicationTypeBuilder` with additional types `Nullable` and `StringEnum`. These types are fairly common in OpenAPI implementations.
22
+
Creates an `enum` union string schema representation.
exportconst Type =newApplicationTypeBuilder() // re-export!
25
+
import { UnionEnum } from'./experimental'
26
+
27
+
28
+
const T =UnionEnum(['A', 'B', 'C']) // const T = {
29
+
// enum: ['A', 'B', 'C']
30
+
// }
31
+
32
+
typeT=Static<typeofT> // type T = 'A' | 'B' | 'C'
33
+
26
34
```
35
+
## UnionOneOf
36
+
37
+
Creates a `oneOf` union representation.
38
+
39
+
40
+
```typescript
41
+
import { UnionOneOf } from'./experimental'
42
+
43
+
44
+
const T =UnionOneOf([ // const T = {
45
+
Type.Literal('A'), // oneOf: [
46
+
Type.Literal('B'), // { const: 'A' },
47
+
Type.Literal('C') // { const: 'B' },
48
+
]) // { const: 'C' },
49
+
// ]
50
+
// }
27
51
28
-
## Experimental Type Builder
52
+
typeT=Static<typeofT> // type T = 'A' | 'B' | 'C'
29
53
30
-
The `experimental.ts` file provided with this example shows advanced usage by creating complex types for potential inclusion in the TypeBox library in later revisions. It is offered for reference, experimentation and is open to contributor submission.
Copy file name to clipboardExpand all lines: example/formats/readme.md
+3-27
Original file line number
Diff line number
Diff line change
@@ -1,35 +1,11 @@
1
-
# String Formats
1
+
# Formats
2
2
3
-
TypeBox does not implement any string formats by default. However it is possible to register user defined formats using the `FormatRegistry`. Once registered, the format becomes available to both `Value` and `TypeCompiler` modules.
3
+
This example provides TypeCompiler supported versions of the `ajv-formats` package.
4
4
5
-
## FormatRegistry
6
-
7
-
The following shows basic usage of the format registry
0 commit comments