@@ -247,12 +247,8 @@ export class FormState<T, State = DefaultState, Error extends string = DefaultEr
247247 * @param notifyParent Should this form notify the parent form about this change?
248248 */
249249 public setValues ( values : Partial < T > , validate ?: boolean , isDefault : boolean = false , notifyChild : boolean = true , notifyParent : boolean = true ) {
250- // No set is used because this could cause problems with array keys, which must always be in the right order
251250 let keys = Object . keys ( isDefault ? this . defaultValues : this . values ) ;
252- let newKeys = Object . keys ( values ) ;
253- for ( let i = 0 ; i < newKeys . length ; i ++ ) {
254- if ( ! keys . includes ( newKeys [ i ] ) ) keys . push ( newKeys [ i ] ) ;
255- }
251+ addDistinct ( keys , Object . keys ( values ) ) ;
256252
257253 // Traverse backwards, so when removing array items, the whole array gets shifted in the right direction
258254 for ( let i = keys . length - 1 ; i >= 0 ; i -- ) {
@@ -412,10 +408,10 @@ export class FormState<T, State = DefaultState, Error extends string = DefaultEr
412408 public setState ( newState : State , notifyChild : boolean = true , notifyParent : boolean = true ) {
413409 this . _state = newState ;
414410
415- let c = Object . keys ( this . values ) ;
411+ let c = Object . keys ( this . values ) as ( keyof T ) [ ] ;
416412 if ( notifyChild ) c . forEach ( ( e ) => this . childMap [ e ] ?. setState ( newState , true , false ) ) ;
417413
418- c . forEach ( ( e ) => this . fireListeners ( e as keyof T ) ) ;
414+ c . forEach ( ( e ) => this . fireListeners ( e ) ) ;
419415 this . fireAnyListeners ( ) ;
420416 if ( notifyParent ) this . updateParentState ( ) ;
421417 }
0 commit comments