File tree Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -48,37 +48,28 @@ Custom types check:
48
48
49
49
import {Type as T , StrictType as ST , check } from ' typed-props'
50
50
51
- const userType = T .shape ({
51
+ const type = T .shape ({
52
52
id: T .number .isRequired ,
53
53
name: T .string .isRequired ,
54
54
email: T .string ,
55
55
}).isRequired
56
56
57
57
// Or
58
58
59
- const userType = ST .shape ({
59
+ const type = ST .shape ({
60
60
id: ST .number ,
61
61
name: ST .string ,
62
62
email: ST .string .optional ,
63
63
})
64
64
65
- check ( {
65
+ const data = {
66
66
id: ' 1' ,
67
67
name: null
68
- }, userType); // Produce an array of issues
69
-
70
- // Type behavs like Facebook's PropTypes, it requires isRequire to be set
71
- // to infiltrate undefined properties
72
- check (1 , Type .number ) // -> [] Valid
73
- check (undefined , Type .number ) // -> [] Valid
74
-
75
- check (1 , StrictType .number ) // -> [] Valid
76
- check (undefined , StrictType .number ) // -> [Issue] Invalid
77
-
78
- // There is a way to make type defined as strict optional.
79
- check (undefined , StrictType .number .optional ) // -> [] Valid
68
+ }
80
69
81
- check ({count: 1 }, Type .shape ({count: Type .number }))
70
+ const issues = check (data, type)
71
+ typeof issues // Array
72
+ issues .length // 1
82
73
```
83
74
84
75
### Output
You can’t perform that action at this time.
0 commit comments