@@ -49,9 +49,8 @@ const personValidator = createValidator({
49
49
50
50
if ( personValidator ( input ) ) {
51
51
assertType < string > ( input . name )
52
- assertType < number | undefined > ( input . age )
53
- input . age === undefined
54
- input . age === 1
52
+ if ( typeof input . age !== 'undefined' ) assertType < number > ( input . age )
53
+ if ( typeof input . age !== 'number' ) assertType < undefined > ( input . age )
55
54
}
56
55
57
56
const namesValidator = createValidator ( {
@@ -139,7 +138,8 @@ const user2Validator = createValidator({
139
138
140
139
if ( user2Validator ( input ) ) {
141
140
assertType < { first : string | undefined , last : string } > ( input . name )
142
- assertType < string | undefined > ( input . name . first )
141
+ if ( typeof input . name . first !== 'undefined' ) assertType < string > ( input . name . first )
142
+ if ( typeof input . name . first !== 'string' ) assertType < undefined > ( input . name . first )
143
143
assertType < string > ( input . name . last )
144
144
145
145
if ( input . items !== undefined ) {
@@ -165,7 +165,9 @@ const specificValuesValidator = createValidator({
165
165
} )
166
166
167
167
if ( specificValuesValidator ( input ) ) {
168
- assertType < true | 1000 | 'XX' > ( input )
168
+ if ( input !== true && input !== 1000 ) assertType < 'XX' > ( input )
169
+ if ( input !== 1000 && input !== 'XX' ) assertType < true > ( input )
170
+ if ( input !== 'XX' && input !== true ) assertType < 1000 > ( input )
169
171
}
170
172
171
173
const metricValidator = createValidator ( {
@@ -184,3 +186,21 @@ if (metricValidator(input)) {
184
186
assertType < 'page-view' > ( input . name )
185
187
assertType < string > ( input . page )
186
188
}
189
+
190
+ const noRequiredFieldsValidator = createValidator ( {
191
+ type : 'object' ,
192
+ properties : {
193
+ a : { type : 'string' } ,
194
+ b : { type : 'string' } ,
195
+ c : { type : 'string' }
196
+ }
197
+ } )
198
+
199
+ if ( noRequiredFieldsValidator ( input ) ) {
200
+ if ( typeof input . a !== 'string' ) assertType < undefined > ( input . a )
201
+ if ( typeof input . b !== 'string' ) assertType < undefined > ( input . b )
202
+ if ( typeof input . c !== 'string' ) assertType < undefined > ( input . c )
203
+ if ( typeof input . a !== 'undefined' ) assertType < string > ( input . a )
204
+ if ( typeof input . b !== 'undefined' ) assertType < string > ( input . b )
205
+ if ( typeof input . c !== 'undefined' ) assertType < string > ( input . c )
206
+ }
0 commit comments