Decompose monolithic readme into docs/ directory structure
This commit is contained in:
43
docs/types/recursive.md
Normal file
43
docs/types/recursive.md
Normal file
@@ -0,0 +1,43 @@
|
||||
[Overview](../overview.md) | [Installation](../installation.md) | [Usage](../usage.md) | **Types** | [Values](../values/) | [Syntax](../syntax/) | [TypeRegistry](../type-registry.md) | [TypeCheck](../type-check.md)
|
||||
|
||||
# Recursive Types
|
||||
|
||||
Use the Recursive function to create recursive types.
|
||||
|
||||
```typescript
|
||||
const Node = Type.Recursive(
|
||||
(This) =>
|
||||
Type.Object({
|
||||
// const Node = {
|
||||
id: Type.String(), // $id: 'Node',
|
||||
nodes: Type.Array(This), // type: 'object',
|
||||
}),
|
||||
{ $id: "Node" }
|
||||
); // properties: {
|
||||
// id: {
|
||||
// type: 'string'
|
||||
// },
|
||||
// nodes: {
|
||||
// type: 'array',
|
||||
// items: {
|
||||
// $ref: 'Node'
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// required: [
|
||||
// 'id',
|
||||
// 'nodes'
|
||||
// ]
|
||||
// }
|
||||
|
||||
type Node = Static<typeof Node>; // type Node = {
|
||||
// id: string
|
||||
// nodes: Node[]
|
||||
// }
|
||||
|
||||
function test(node: Node) {
|
||||
const id = node.nodes[0].nodes[0].id; // id is string
|
||||
}
|
||||
```
|
||||
|
||||
Back to [Home](../../readme.md)
|
||||
Reference in New Issue
Block a user