@@ -146,7 +146,7 @@ export default function validateField (props: ValidateFieldProps): ValidationErr
146146 affectedKeyGeneric : affectedKeyGeneric ?? undefined ,
147147 keysToValidate
148148 } ) ) {
149- // Perform validation for this key
149+ // Perform validation for this key
150150 for ( const currentDef of schema . getDefinitions ( affectedKey , null , functionsContext ) ) {
151151 def = currentDef
152152
@@ -171,7 +171,7 @@ export default function validateField (props: ValidateFieldProps): ValidationErr
171171 // Loop through each of the definitions in the SimpleSchemaGroup.
172172 // If the value matches any, we are valid and can stop checking the rest.
173173 for ( const [ typeIndex , typeDef ] of currentDef . type . entries ( ) ) {
174- // If the type is SimpleSchema.Any, then it is valid
174+ // If the type is SimpleSchema.Any, then it is valid
175175 if ( typeDef === SimpleSchema . Any ) break
176176
177177 const nonAnyTypeDefinition = typeDef as SchemaKeyDefinitionWithOneType
@@ -225,7 +225,7 @@ export default function validateField (props: ValidateFieldProps): ValidationErr
225225 }
226226 }
227227
228- if ( SimpleSchema . isSimpleSchema ( nonAnyTypeDefinition . type ) ) {
228+ if ( val !== undefined && SimpleSchema . isSimpleSchema ( nonAnyTypeDefinition . type ) ) {
229229 const itemErrors = validateField ( {
230230 extendedCustomContext,
231231 keysToValidate,
@@ -242,8 +242,8 @@ export default function validateField (props: ValidateFieldProps): ValidationErr
242242
243243 // As soon as we find a type for which the value is valid, stop checking more
244244 if ( fieldValidationErrorsForThisType . length === 0 ) {
245- // One we have chosen a valid schema, there is no need to validate the
246- // properties of this object because we validated all the way down
245+ // One we have chosen a valid schema, there is no need to validate the
246+ // properties of this object because we validated all the way down
247247 if ( SimpleSchema . isSimpleSchema ( nonAnyTypeDefinition . type ) ) {
248248 return fieldValidationErrors
249249 }
@@ -261,7 +261,7 @@ export default function validateField (props: ValidateFieldProps): ValidationErr
261261
262262 // Mark invalid if not found in schema
263263 if ( def == null ) {
264- // We don't need KEY_NOT_IN_SCHEMA error for $unset and we also don't need to continue
264+ // We don't need KEY_NOT_IN_SCHEMA error for $unset and we also don't need to continue
265265 if (
266266 op === '$unset' ||
267267 ( op === '$currentDate' && affectedKey . endsWith ( '.$type' ) )
0 commit comments