Socket
Socket
Sign inDemoInstall

@sinclair/typebox

Package Overview
Dependencies
0
Maintainers
1
Versions
310
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.17.4 to 0.17.5

2

package.json
{
"name": "@sinclair/typebox",
"version": "0.17.4",
"version": "0.17.5",
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",

@@ -5,0 +5,0 @@ "keywords": [

@@ -52,2 +52,3 @@ <div align='center'>

- [Reference Types](#Reference-Types)
- [Recursive Types](#Recursive-Types)
- [Strict](#Strict)

@@ -490,2 +491,40 @@ - [Interfaces](#Interfaces)

<a name="Recursive-Types"></a>
### Recursive Types
TypeBox provides rudimentary support for recursive types. This is handled via the `Type.Rec(...)` method. The following creates a `Node` type that contains an array of inner `nodes`. Please note that due to current recursion limits on TypeScript inference, it's currently not possible for TypeBox to statically infer for recursive types. Instead TypeBox will resolve inner recursive types as `any`.
```typescript
const Node = Type.Rec(Self => Type.Object({ // const Node = {
id: Type.String(), // definitions: {
nodes: Type.Array(Self), // self: {
})) // type: 'object',
// properties: {
// id: {
// type: 'string'
// },
// nodes: {
// type: 'array',
// items: {
// $ref: '#/definitions/self'
// }
// }
// }
// },
// $ref: '#/definitions/self'
// }
type Node = Static<typeof Node> // type Node = {
// id: string
// nodes: any[]
//
function walk(node: Node) {
for(const inner of node.nodes) {
walk(inner as Node) // Assert inner as Node
}
}
```
<a name="Strict"></a>

@@ -492,0 +531,0 @@

@@ -297,3 +297,5 @@ export declare const ReadonlyOptionalModifier: unique symbol;

Ref<T extends TBox<TDefinitions>, K extends keyof T['definitions']>(box: T, key: K): T['definitions'][K];
/** `EXPERIMENTAL` Creates a recursive type. */
Rec<T extends TSchema>(callback: (self: TAny) => T): T;
}
export declare const Type: TypeBuilder;

@@ -296,4 +296,9 @@ "use strict";

}
/** `EXPERIMENTAL` Creates a recursive type. */
Rec(callback) {
const self = callback({ $ref: '#/definitions/self' });
return { definitions: { self }, $ref: "#/definitions/self" };
}
}
exports.TypeBuilder = TypeBuilder;
exports.Type = new TypeBuilder();
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc