11import cloneDeep from 'lodash/cloneDeep' ;
22import get from 'lodash/get' ;
33import set from 'lodash/set' ;
4+ import setWith from 'lodash/setWith' ;
45
56import { ErrorSchema } from './types' ;
67import { ERRORS_KEY } from './constants' ;
@@ -37,12 +38,12 @@ export default class ErrorSchemaBuilder<T = any> {
3738 * @returns - The error block for the given `pathOfError` or the root if not provided
3839 * @private
3940 */
40- private getOrCreateErrorBlock ( pathOfError ?: string | string [ ] ) {
41+ private getOrCreateErrorBlock ( pathOfError ?: string | ( string | number ) [ ] ) {
4142 const hasPath = ( Array . isArray ( pathOfError ) && pathOfError . length > 0 ) || typeof pathOfError === 'string' ;
4243 let errorBlock : ErrorSchema = hasPath ? get ( this . errorSchema , pathOfError ) : this . errorSchema ;
4344 if ( ! errorBlock && pathOfError ) {
4445 errorBlock = { } ;
45- set ( this . errorSchema , pathOfError , errorBlock ) ;
46+ setWith ( this . errorSchema , pathOfError , errorBlock , Object ) ;
4647 }
4748 return errorBlock ;
4849 }
@@ -65,7 +66,7 @@ export default class ErrorSchemaBuilder<T = any> {
6566 * @param [pathOfError] - The optional path into the `ErrorSchema` at which to add the error(s)
6667 * @returns - The `ErrorSchemaBuilder` object for chaining purposes
6768 */
68- addErrors ( errorOrList : string | string [ ] , pathOfError ?: string | string [ ] ) {
69+ addErrors ( errorOrList : string | string [ ] , pathOfError ?: string | ( string | number ) [ ] ) {
6970 const errorBlock : ErrorSchema = this . getOrCreateErrorBlock ( pathOfError ) ;
7071 let errorsList = get ( errorBlock , ERRORS_KEY ) ;
7172 if ( ! Array . isArray ( errorsList ) ) {
@@ -89,7 +90,7 @@ export default class ErrorSchemaBuilder<T = any> {
8990 * @param [pathOfError] - The optional path into the `ErrorSchema` at which to set the error(s)
9091 * @returns - The `ErrorSchemaBuilder` object for chaining purposes
9192 */
92- setErrors ( errorOrList : string | string [ ] , pathOfError ?: string | string [ ] ) {
93+ setErrors ( errorOrList : string | string [ ] , pathOfError ?: string | ( string | number ) [ ] ) {
9394 const errorBlock : ErrorSchema = this . getOrCreateErrorBlock ( pathOfError ) ;
9495 // Effectively clone the array being given to prevent accidental outside manipulation of the given list
9596 const listToAdd = Array . isArray ( errorOrList ) ? [ ...errorOrList ] : [ errorOrList ] ;
@@ -104,7 +105,7 @@ export default class ErrorSchemaBuilder<T = any> {
104105 * @param [pathOfError] - The optional path into the `ErrorSchema` at which to clear the error(s)
105106 * @returns - The `ErrorSchemaBuilder` object for chaining purposes
106107 */
107- clearErrors ( pathOfError ?: string | string [ ] ) {
108+ clearErrors ( pathOfError ?: string | ( string | number ) [ ] ) {
108109 const errorBlock : ErrorSchema = this . getOrCreateErrorBlock ( pathOfError ) ;
109110 set ( errorBlock , ERRORS_KEY , [ ] ) ;
110111 return this ;
0 commit comments