@@ -234,22 +234,28 @@ export function replaceInvalidDefaults<T extends Record<string, unknown>>(
234234 for ( const error of Errors ) {
235235 if ( ! error . path ) continue ;
236236
237- Defaults_traverseAndReplace ( {
238- path : error . path ,
239- value : pathExists ( Defaults , error . path ) ?. value
240- } ) ;
237+ Defaults_traverseAndReplace (
238+ {
239+ path : error . path ,
240+ value : pathExists ( Defaults , error . path ) ?. value
241+ } ,
242+ true
243+ ) ;
241244 }
242245 }
243246
244247 //#endregion
245248
246249 //#region Defaults
247250
248- function Defaults_traverseAndReplace ( defaultPath : {
249- path : ( string | number | symbol ) [ ] ;
250- // eslint-disable-next-line @typescript-eslint/no-explicit-any
251- value : any ;
252- } ) : void {
251+ function Defaults_traverseAndReplace (
252+ defaultPath : {
253+ path : ( string | number | symbol ) [ ] ;
254+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
255+ value : any ;
256+ } ,
257+ traversingErrors = false
258+ ) : void {
253259 const currentPath = defaultPath . path ;
254260 if ( ! currentPath || ! currentPath [ 0 ] ) return ;
255261 if ( typeof currentPath [ 0 ] === 'string' && preprocessed ?. includes ( currentPath [ 0 ] ) ) return ;
@@ -279,9 +285,11 @@ export function replaceInvalidDefaults<T extends Record<string, unknown>>(
279285 const typePath = currentPath . filter ( ( p ) => / \D / . test ( String ( p ) ) ) ;
280286 const pathTypes = traversePath ( Types , typePath , ( path ) => {
281287 //console.log(path.path, path.value); //debug
282- return '__items' in path . value ? path . value . __items : path . value ;
288+ return path . value && '__items' in path . value ? path . value . __items : path . value ;
283289 } ) ;
284290 if ( ! pathTypes ) {
291+ // Return if checking for errors, as there may be deep errors that doesn't exist in the defaults.
292+ if ( traversingErrors ) return ;
285293 throw new SchemaError ( 'No types found for defaults' , currentPath ) ;
286294 }
287295
0 commit comments