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
TypeBox has support for parsing TypeScript syntax at runtime as well as statically in the type system. This feature offers a syntactical frontend to the TypeBox type builder.
1309
+
TypeBox includes support for parsing TypeScript annotation syntax into TypeBox schematics.
1310
1310
1311
-
Syntax types are available via optional import.
1311
+
This feature is provided via optional import.
1312
1312
1313
1313
```typescript
1314
1314
import { Syntax } from'@sinclair/typebox/syntax'
@@ -1318,20 +1318,25 @@ import { Syntax } from '@sinclair/typebox/syntax'
1318
1318
1319
1319
### Create
1320
1320
1321
-
Use the Syntax function to create TypeBox types from TypeScript syntax
1321
+
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))
1322
1322
1323
1323
```typescript
1324
1324
constT=Syntax(`{ x: number, y: number }`) // const T: TObject<{
1325
1325
// x: TNumber,
1326
1326
// y: TNumber
1327
1327
// }>
1328
+
1329
+
typeT=Static<typeofT>// type T = {
1330
+
// x: number,
1331
+
// y: number
1332
+
// }
1328
1333
```
1329
1334
1330
1335
<a name="syntax-parameters"></a>
1331
1336
1332
1337
### Parameters
1333
1338
1334
-
Syntax types can be parameterized to receive exterior types.
1339
+
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))
1335
1340
1336
1341
```typescript
1337
1342
constT=Syntax(`{ x: number, y: number }`) // const T: TObject<{
@@ -1345,35 +1350,19 @@ const S = Syntax({ T }, `Partial<T>`) // const S: TObject<{
1345
1350
// }>
1346
1351
```
1347
1352
1348
-
<a name='syntax-options'></a>
1349
-
1350
-
### Options
1351
1353
1352
-
Options can be passed via the last parameter
1353
-
1354
-
```typescript
1355
-
constT=Syntax(`number`, { // const T = {
1356
-
minimum: 0, // type: 'number',
1357
-
maximum: 10// minimum: 0,
1358
-
}) // maximum: 10
1359
-
// }
1360
-
```
1361
1354
1362
1355
<a name="syntax-generics"></a>
1363
1356
1364
1357
### Generics
1365
1358
1366
-
Generic types can be created using positional argument types ([Example](https://www.typescriptlang.org/play/?moduleResolution=99&module=199&ts=5.8.0-beta#code/JYWwDg9gTgLgBAbzgZQJ4DsYEMAecC+cAZlBCHAOQACAzsOgMYA2WwUA9DKmAKYBGEHOxoZsOCgChQkWIhTYYwBgWKly1OoxZtO3foMkSGEdDXgAVAAxwAvClG4AFBQCCUAOYBXED0wAeSwA+CgBKIxMzOHMARlt7TCdXD29fGD9o4LDjUwsAJji0BJxnNy8ff1zMiXCcuAA1HgYYaAKHYqQrABoo6O7zfPxugAMECTg4HAAuKMtOsbhUaZi58YAvJdyJfCGwmsiAISw6Ggam6BpWosckU+aoAmHR8an6xrv07tm4IJWF6dvoAFur1voFfutXmcoEDvsCwVsdtUuLw4IdjgCoBc7MgFEo-MieBAiKijsATm9zoFxtT2Ow4ASSeiKZi4k9qeyOZyudyeTzadSXkgXiDFrC4BDrIN5ryZbK5ez+eNRULpl9RSCJQ9pfKdbqFXS1tMVWLRV8IbF8Nq9da5fzCEA))
1359
+
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))
1367
1360
1368
1361
```typescript
1369
-
constT0=Syntax('Argument<0>')
1370
-
constT1=Syntax('Argument<1>')
1371
-
constT2=Syntax('Argument<2>')
1372
-
1373
-
constVector=Syntax({ T0, T1, T2 }, `{
1374
-
x: T0,
1375
-
y: T1,
1376
-
z: T2
1362
+
constVector=Syntax(`<X, Y, Z> {
1363
+
x: X,
1364
+
y: Y,
1365
+
z: Z
1377
1366
}`)
1378
1367
1379
1368
constBasisVectors=Syntax({ Vector }, `{
@@ -1386,7 +1375,20 @@ type BasisVectors = Static<typeof BasisVectors> // type BasisVectors = {
1386
1375
// x: { x: 1, y: 0, z: 0 },
1387
1376
// y: { x: 0, y: 1, z: 0 },
1388
1377
// z: { x: 0, y: 0, z: 1 }
1389
-
// }
1378
+
// }
1379
+
```
1380
+
1381
+
<a name='syntax-options'></a>
1382
+
1383
+
### Options
1384
+
1385
+
Options can be passed via the last parameter
1386
+
1387
+
```typescript
1388
+
constT=Syntax(`number`, { minimum: 42 }) // const T = {
0 commit comments