@@ -124,7 +124,7 @@ Example:
124
124
Standard checks provided by Facebook's PropTypes:
125
125
126
126
` ` ` javascript
127
- import {Type } from ' typed-props'
127
+ import {Type , TypeStore } from ' typed-props'
128
128
129
129
// Object properties should pass all checks.
130
130
const shape = Type .shape ({
@@ -185,6 +185,31 @@ empty.
185
185
186
186
> ⚠️ .object will fail for arrays and vice versa.
187
187
188
+ ## Named and circular types
189
+
190
+ Using named types it's possible to created nested structures with cross references.
191
+ It could be useful for validating complex data types. Also names help to produce more
192
+ meaningful error reports.
193
+
194
+ ``` javascript
195
+ const store = new TypeStore ()
196
+
197
+ const userType = Type .shape ({
198
+ id: Type .number .isRequired ,
199
+ name: Type .string .isRequired ,
200
+ posts: Type .arrayOf (store .ref (' Post' )),
201
+ })
202
+
203
+ const postType = Type .shape ({
204
+ id: Type .number .isRequired ,
205
+ title: Type .string .isRequired ,
206
+ authors: Type .arrayOf (store .ref (' User' )),
207
+ })
208
+
209
+ store .add (' User' , userType)
210
+ store .add (' Post' , postType)
211
+ ```
212
+
188
213
## Non-standard checks
189
214
190
215
``` javascript
0 commit comments