diff --git a/src/actions.ts b/src/actions.ts index bae8366e..3da26f26 100644 --- a/src/actions.ts +++ b/src/actions.ts @@ -246,7 +246,7 @@ export type Actions = | UnfocusAction | MarkAsSubmittedAction | MarkAsUnsubmittedAction - | AddGroupControlAction + | (TValue extends KeyValue ? AddGroupControlAction : never) | RemoveGroupControlAction | AddArrayControlAction | RemoveArrayControlAction diff --git a/src/array/reducer/move-control.ts b/src/array/reducer/move-control.ts index 7339bef2..e2312e35 100644 --- a/src/array/reducer/move-control.ts +++ b/src/array/reducer/move-control.ts @@ -51,7 +51,7 @@ export function moveControlReducer( let controls = move(state.controls, fromIndex, toIndex); - controls = controls.map((c, i) => updateIdRecursive(c, `${state.id}.${i}`)); + controls = controls.map((c, i) => updateIdRecursive(c, `${state.id}.${i}`)); return computeArrayState( state.id, diff --git a/src/array/reducer/swap-control.ts b/src/array/reducer/swap-control.ts index d4e7f7c6..5c4bca27 100644 --- a/src/array/reducer/swap-control.ts +++ b/src/array/reducer/swap-control.ts @@ -36,7 +36,7 @@ export function swapControlReducer( } let controls = swapArrayValues(state.controls, fromIndex, toIndex); - controls = controls.map((c, i) => (i >= fromIndex || i >= toIndex) ? updateIdRecursive(c, `${state.id}.${i}`) : c); + controls = controls.map((c, i) => (i >= fromIndex || i >= toIndex) ? updateIdRecursive(c, `${state.id}.${i}`) : c); return computeArrayState( state.id, diff --git a/src/boxing.ts b/src/boxing.ts index a53d8638..44395038 100644 --- a/src/boxing.ts +++ b/src/boxing.ts @@ -32,7 +32,7 @@ export function box(value: T): Boxed { } export function unbox(value: T): Unboxed { - if (['string', 'boolean', 'number', 'undefined'].indexOf(typeof value) >= 0 || value === null) { + if (['string', 'boolean', 'number', 'undefined'].indexOf(typeof value) >= 0 || value === null || value === undefined) { return value as unknown as Unboxed; } diff --git a/src/group/directive.ts b/src/group/directive.ts index c5a86b1a..b5c5e807 100644 --- a/src/group/directive.ts +++ b/src/group/directive.ts @@ -2,7 +2,7 @@ import { Directive, HostListener, Inject, Input, OnInit, Optional } from '@angul import { ActionsSubject } from '@ngrx/store'; import { Actions, MarkAsSubmittedAction } from '../actions'; -import { FormGroupState } from '../state'; +import { FormGroupState, KeyValue } from '../state'; // this interface just exists to prevent a direct reference to // `Event` in our code, which otherwise causes issues in NativeScript @@ -13,7 +13,7 @@ interface CustomEvent extends Event { } // tslint:disable-next-line:directive-selector selector: 'form:not([ngrxFormsAction])[ngrxFormState]', }) -export class NgrxFormDirective implements OnInit { +export class NgrxFormDirective implements OnInit { // tslint:disable-next-line:no-input-rename @Input('ngrxFormState') state: FormGroupState; diff --git a/src/group/local-state-directive.ts b/src/group/local-state-directive.ts index d7f2feb6..e67efc06 100644 --- a/src/group/local-state-directive.ts +++ b/src/group/local-state-directive.ts @@ -1,13 +1,14 @@ import { Directive, EventEmitter, Output } from '@angular/core'; import { Actions } from '../actions'; +import { KeyValue } from '../state'; import { NgrxFormDirective } from './directive'; @Directive({ // tslint:disable-next-line:directive-selector selector: 'form[ngrxFormState][ngrxFormsAction]', }) -export class NgrxLocalFormDirective extends NgrxFormDirective { +export class NgrxLocalFormDirective extends NgrxFormDirective { @Output() ngrxFormsAction = new EventEmitter>(); diff --git a/src/group/reducer/add-control.ts b/src/group/reducer/add-control.ts index 6ee32b63..90239789 100644 --- a/src/group/reducer/add-control.ts +++ b/src/group/reducer/add-control.ts @@ -15,11 +15,11 @@ export function addControlReducer( } if (state.controls.hasOwnProperty(action.name)) { - throw new Error(`Group '${state.id}' already has child control '${action.name}'!`); // `; + throw new Error(`Group '${state.id}' already has child control '${action.name as string}'!`); // `; } const controls = Object.assign({}, state.controls, { - [action.name]: createChildState(`${state.id}.${action.name}`, action.value), + [action.name]: createChildState(`${state.id}.${action.name as string}`, action.value), }); return computeGroupState( diff --git a/src/group/reducer/remove-control.ts b/src/group/reducer/remove-control.ts index 82b62e31..8d9bf974 100644 --- a/src/group/reducer/remove-control.ts +++ b/src/group/reducer/remove-control.ts @@ -15,7 +15,7 @@ export function removeControlReducer( } if (!state.controls.hasOwnProperty(action.name)) { - throw new Error(`Group '${state.id}' does not have child control '${action.name}'!`); // `; + throw new Error(`Group '${state.id}' does not have child control '${action.name as string}'!`); // `; } const controls = Object.assign({}, state.controls); diff --git a/src/group/reducer/set-value.ts b/src/group/reducer/set-value.ts index a843b047..94b6210f 100644 --- a/src/group/reducer/set-value.ts +++ b/src/group/reducer/set-value.ts @@ -1,6 +1,6 @@ import { Actions, SetValueAction } from '../../actions'; import { formStateReducer } from '../../reducer'; -import { computeGroupState, createChildState, FormGroupControls, FormGroupState, KeyValue } from '../../state'; +import { AbstractControlState, computeGroupState, createChildState, FormGroupControls, FormGroupState, KeyValue } from '../../state'; import { childReducer } from './util'; export function setValueReducer( @@ -31,7 +31,7 @@ export function setValueReducer( if (!state.controls[key]) { Object.assign(c, { [key]: createChildState(`${state.id}.${key}`, value[key]) }); } else { - Object.assign(c, { [key]: formStateReducer(state.controls[key], new SetValueAction(state.controls[key].id, value[key])) }); + Object.assign(c, { [key]: formStateReducer(state.controls[key], new SetValueAction((state.controls[key] as AbstractControlState).id, value[key])) }); } return c; }, {} as FormGroupControls); diff --git a/src/group/reducer/util.ts b/src/group/reducer/util.ts index 0f80a9d5..0c023027 100644 --- a/src/group/reducer/util.ts +++ b/src/group/reducer/util.ts @@ -1,6 +1,6 @@ import { Actions } from '../../actions'; import { formStateReducer } from '../../reducer'; -import { computeGroupState, FormGroupControls, FormGroupState, FormState, KeyValue } from '../../state'; +import { AbstractControlState, computeGroupState, FormGroupControls, FormGroupState, FormState, KeyValue } from '../../state'; export function dispatchActionPerChild( controls: FormGroupControls, @@ -9,7 +9,7 @@ export function dispatchActionPerChild( let hasChanged = false; const newControls = Object.keys(controls) .reduce((c, key) => { - Object.assign(c, { [key]: formStateReducer(controls[key], actionCreator(controls[key].id)) }); + Object.assign(c, { [key]: formStateReducer(controls[key], actionCreator((controls[key] as AbstractControlState).id)) }); hasChanged = hasChanged || c[key] !== controls[key]; return c; }, {} as FormGroupControls); diff --git a/src/reducer.ts b/src/reducer.ts index 810bdc70..8fd3002b 100644 --- a/src/reducer.ts +++ b/src/reducer.ts @@ -4,7 +4,7 @@ import { Actions, ALL_NGRX_FORMS_ACTION_TYPES } from './actions'; import { formArrayReducer } from './array/reducer'; import { formControlReducer } from './control/reducer'; import { formGroupReducer } from './group/reducer'; -import { AbstractControlState, FormArrayState, FormControlState, FormState, isArrayState, isFormState, isGroupState } from './state'; +import { AbstractControlState, FormArrayState, FormControlState, FormState, isArrayState, isFormState, isGroupState, KeyValue } from './state'; import { ProjectFn } from './update-function/util'; export function formStateReducer( @@ -88,7 +88,7 @@ function reduceNestedFormState(state: TState, key: keyof TState, action: }; } -function reduceNestedFormStates(state: TState, action: Action): TState { +function reduceNestedFormStates(state: TState, action: Action): TState { return Object.keys(state).reduce((s, key) => reduceNestedFormState(s, key as keyof TState, action), state); } @@ -141,7 +141,7 @@ export function onNgrxFormsAction< * The update function is passed the form state and the updated containing state * as parameters. */ -export function wrapReducerWithFormStateUpdate>( +export function wrapReducerWithFormStateUpdate>( reducer: ActionReducer, formStateLocator: (state: TState) => TFormState, updateFn: (formState: TFormState, state: TState) => TFormState, diff --git a/src/state.ts b/src/state.ts index 74114319..a7a9cf6b 100644 --- a/src/state.ts +++ b/src/state.ts @@ -229,7 +229,7 @@ export interface FormControlState extends /** * This type represents the child control states of a form group. */ -export type FormGroupControls = { +export type FormGroupControls = { readonly [controlId in keyof TValue]: FormState; }; @@ -576,7 +576,7 @@ export type InferredFormState> = : T extends InferenceWrapper ? FormArrayState // group - : T extends InferenceWrapper ? FormGroupState + : T extends InferenceWrapper ? U extends KeyValue ? FormGroupState : never // fallback type (this case should never (no pun intended) be hit) : never @@ -605,7 +605,7 @@ export function isArrayState(state: any): state is FormArrayState< /** * This function determines if a value is a group state. */ -export function isGroupState(state: any): state is FormGroupState { +export function isGroupState(state: any): state is FormGroupState { return isFormState(state) && state.hasOwnProperty('controls') && !Array.isArray((state as any).controls) && typeof (state as any).controls !== 'function'; } @@ -684,8 +684,9 @@ export function getFormGroupValue( ): TValue { let hasChanged = Object.keys(originalValue).length !== Object.keys(controls).length; const newValue = Object.keys(controls).reduce((res, key: keyof TValue) => { - hasChanged = hasChanged || originalValue[key] !== controls[key].value; - res[key] = controls[key].value; + const control = controls[key] as AbstractControlState; + hasChanged = hasChanged || originalValue[key] !== control.value; + res[key] = control.value; return res; }, {} as TValue); @@ -703,10 +704,11 @@ export function getFormGroupErrors( .reduce((res, key) => Object.assign(res, { [key]: originalErrors[key] }), {} as ValidationErrors); const newErrors = Object.keys(controls).reduce((res, key: any) => { - const controlErrors = controls[key].errors; + const control = controls[key] as AbstractControlState; + const controlErrors = control.errors; if (!isEmpty(controlErrors)) { hasChanged = hasChanged || originalErrors[`_${key}`] !== controlErrors; - Object.assign(res, { [`_${key}`]: controls[key].errors }); + Object.assign(res, { [`_${key}`]: control.errors }); } else { hasChanged = hasChanged || originalErrors.hasOwnProperty(`_${key}`); } @@ -736,11 +738,11 @@ export function computeGroupState( value = getFormGroupValue(controls, value); errors = getFormGroupErrors(controls, errors); const isValid = isEmpty(errors); - const isDirty = flags.wasOrShouldBeDirty || Object.keys(controls).some(key => controls[key].isDirty); - const isEnabled = flags.wasOrShouldBeEnabled || Object.keys(controls).some(key => controls[key].isEnabled); - const isTouched = flags.wasOrShouldBeTouched || Object.keys(controls).some(key => controls[key].isTouched); - const isSubmitted = flags.wasOrShouldBeSubmitted || Object.keys(controls).some(key => controls[key].isSubmitted); - const isValidationPending = pendingValidations.length > 0 || Object.keys(controls).some(key => controls[key].isValidationPending); + const isDirty = flags.wasOrShouldBeDirty || Object.keys(controls).some(key => (controls[key] as AbstractControlState).isDirty); + const isEnabled = flags.wasOrShouldBeEnabled || Object.keys(controls).some(key => (controls[key] as AbstractControlState).isEnabled); + const isTouched = flags.wasOrShouldBeTouched || Object.keys(controls).some(key => (controls[key] as AbstractControlState).isTouched); + const isSubmitted = flags.wasOrShouldBeSubmitted || Object.keys(controls).some(key => (controls[key] as AbstractControlState).isSubmitted); + const isValidationPending = pendingValidations.length > 0 || Object.keys(controls).some(key => (controls[key] as AbstractControlState).isValidationPending); return { id, value, @@ -774,7 +776,7 @@ export function createFormGroupState( initialValue: TValue, ): FormGroupState { const controls = Object.keys(initialValue) - .map((key: keyof TValue) => [key, createChildState(`${id}.${key}`, initialValue[key])] as [string, FormState]) + .map((key: keyof TValue) => [key, createChildState(`${id}.${key as string}`, initialValue[key])] as [string, FormState]) .reduce((res, [controlId, state]) => Object.assign(res, { [controlId]: state }), {} as FormGroupControls); return computeGroupState(id, controls, initialValue, {}, [], {}, { wasOrShouldBeEnabled: true }); diff --git a/src/update-function/disable.ts b/src/update-function/disable.ts index 76f25b29..2c1d7058 100644 --- a/src/update-function/disable.ts +++ b/src/update-function/disable.ts @@ -1,5 +1,5 @@ import { DisableAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -21,7 +21,7 @@ export function disable(state: FormArrayState): FormArrayState(state: FormGroupState): FormGroupState; +export function disable(state: FormGroupState): FormGroupState; /** * This update function takes a form state and disables it. For groups and arrays also diff --git a/src/update-function/enable.ts b/src/update-function/enable.ts index 41793912..0c75c7ce 100644 --- a/src/update-function/enable.ts +++ b/src/update-function/enable.ts @@ -1,5 +1,5 @@ import { EnableAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -15,7 +15,7 @@ export function enable(state: FormArrayState): FormArrayState(state: FormGroupState): FormGroupState; +export function enable(state: FormGroupState): FormGroupState; /** * This update function takes a form state and enables it. For groups and arrays also diff --git a/src/update-function/mark-as-dirty.ts b/src/update-function/mark-as-dirty.ts index acf08ef9..6337afb4 100644 --- a/src/update-function/mark-as-dirty.ts +++ b/src/update-function/mark-as-dirty.ts @@ -1,5 +1,5 @@ import { MarkAsDirtyAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -15,7 +15,7 @@ export function markAsDirty(state: FormArrayState): FormArraySta /** * This update function takes a form group state and marks it and all of its children as dirty. */ -export function markAsDirty(state: FormGroupState): FormGroupState; +export function markAsDirty(state: FormGroupState): FormGroupState; /** * This update function takes a state and marks it as dirty. For groups and arrays this also marks diff --git a/src/update-function/mark-as-pristine.ts b/src/update-function/mark-as-pristine.ts index 921bc3e9..6437012f 100644 --- a/src/update-function/mark-as-pristine.ts +++ b/src/update-function/mark-as-pristine.ts @@ -1,5 +1,5 @@ import { MarkAsPristineAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -15,7 +15,7 @@ export function markAsPristine(state: FormArrayState): FormArray /** * This update function takes a form group state and marks it and all of its children as pristine. */ -export function markAsPristine(state: FormGroupState): FormGroupState; +export function markAsPristine(state: FormGroupState): FormGroupState; /** * This update function takes a state and marks it as pristine. For groups and arrays this also marks diff --git a/src/update-function/mark-as-submitted.ts b/src/update-function/mark-as-submitted.ts index b96eb1c4..8068d186 100644 --- a/src/update-function/mark-as-submitted.ts +++ b/src/update-function/mark-as-submitted.ts @@ -1,5 +1,5 @@ import { MarkAsSubmittedAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -15,7 +15,7 @@ export function markAsSubmitted(state: FormArrayState): FormArra /** * This update function takes a form group state and marks it and all of its children as submitted. */ -export function markAsSubmitted(state: FormGroupState): FormGroupState; +export function markAsSubmitted(state: FormGroupState): FormGroupState; /** * This update function takes a state and marks it as submitted. For groups and arrays this also marks diff --git a/src/update-function/mark-as-touched.ts b/src/update-function/mark-as-touched.ts index ea4b1756..dece23c0 100644 --- a/src/update-function/mark-as-touched.ts +++ b/src/update-function/mark-as-touched.ts @@ -1,5 +1,5 @@ import { MarkAsTouchedAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -15,7 +15,7 @@ export function markAsTouched(state: FormArrayState): FormArrayS /** * This update function takes a form group state and marks it and all of its children as touched. */ -export function markAsTouched(state: FormGroupState): FormGroupState; +export function markAsTouched(state: FormGroupState): FormGroupState; /** * This update function takes a state and marks it as touched. For groups and arrays this also marks diff --git a/src/update-function/mark-as-unsubmitted.ts b/src/update-function/mark-as-unsubmitted.ts index 98abf154..487db05a 100644 --- a/src/update-function/mark-as-unsubmitted.ts +++ b/src/update-function/mark-as-unsubmitted.ts @@ -1,5 +1,5 @@ import { MarkAsUnsubmittedAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -15,7 +15,7 @@ export function markAsUnsubmitted(state: FormArrayState): FormAr /** * This update function takes a form group state and marks it and all of its children as unsubmitted. */ -export function markAsUnsubmitted(state: FormGroupState): FormGroupState; +export function markAsUnsubmitted(state: FormGroupState): FormGroupState; /** * This update function takes a state and marks it as unsubmitted. For groups and arrays this also marks diff --git a/src/update-function/mark-as-untouched.ts b/src/update-function/mark-as-untouched.ts index 9ed114ad..57284dce 100644 --- a/src/update-function/mark-as-untouched.ts +++ b/src/update-function/mark-as-untouched.ts @@ -1,5 +1,5 @@ import { MarkAsUntouchedAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -15,7 +15,7 @@ export function markAsUntouched(state: FormArrayState): FormArra /** * This update function takes a form group state and marks it and all of its children as untouched. */ -export function markAsUntouched(state: FormGroupState): FormGroupState; +export function markAsUntouched(state: FormGroupState): FormGroupState; /** * This update function takes a state and marks it as untouched. For groups and arrays this also marks diff --git a/src/update-function/reset.ts b/src/update-function/reset.ts index fd8e0552..5242e052 100644 --- a/src/update-function/reset.ts +++ b/src/update-function/reset.ts @@ -1,5 +1,5 @@ import { ResetAction } from '../actions'; -import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState } from '../state'; +import { AbstractControlState, FormArrayState, FormControlState, FormControlValueTypes, FormGroupState, FormState, KeyValue } from '../state'; import { abstractControlReducer } from './util'; /** @@ -18,7 +18,7 @@ export function reset(state: FormArrayState): FormArrayState(state: FormGroupState): FormGroupState; +export function reset(state: FormGroupState): FormGroupState; /** * This update function takes a state and marks it as pristine, untouched, and diff --git a/src/update-function/set-errors.ts b/src/update-function/set-errors.ts index 27324b9e..5526e2f6 100644 --- a/src/update-function/set-errors.ts +++ b/src/update-function/set-errors.ts @@ -40,10 +40,11 @@ export function setErrors( ...rest: ValidationErrors[] ) { if (isFormState(errorsOrErrorsArrayOrState)) { + const state = errorsOrErrorsArrayOrState as AbstractControlState; const errorsArray = Array.isArray(errorsOrErrorsArray) ? errorsOrErrorsArray : [errorsOrErrorsArray!]; const errors = errorsArray.concat(...rest).reduce((agg, err) => Object.assign(agg, err), {} as ValidationErrors); - return formStateReducer(errorsOrErrorsArrayOrState, new SetErrorsAction(errorsOrErrorsArrayOrState.id, errors)); + return formStateReducer(state, new SetErrorsAction(state.id, errors)); } let errorsArray = Array.isArray(errorsOrErrorsArrayOrState) ? errorsOrErrorsArrayOrState : [errorsOrErrorsArrayOrState]; diff --git a/src/update-function/set-user-defined-property.ts b/src/update-function/set-user-defined-property.ts index f3af3bb9..f754a0fb 100644 --- a/src/update-function/set-user-defined-property.ts +++ b/src/update-function/set-user-defined-property.ts @@ -17,7 +17,8 @@ export function setUserDefinedProperty(state: AbstractControlState(nameOrState: string | FormState, valueOrName: any | string, value?: any) { if (isFormState(nameOrState)) { - return formStateReducer(nameOrState, new SetUserDefinedPropertyAction(nameOrState.id, valueOrName, value)); + const state = nameOrState as AbstractControlState; + return formStateReducer(nameOrState, new SetUserDefinedPropertyAction(state.id, valueOrName, value)); } return (s: AbstractControlState) => setUserDefinedProperty(ensureState(s), nameOrState as string, valueOrName); diff --git a/src/update-function/update-group.ts b/src/update-function/update-group.ts index ba3f1291..d98a50c9 100644 --- a/src/update-function/update-group.ts +++ b/src/update-function/update-group.ts @@ -73,7 +73,7 @@ const groupUpdateFn = updateGroup( const updatedState = groupUpdateFn(state); ``` */ -export function updateGroup( +export function updateGroup( updateFn: StateUpdateFns, ...updateFnsArr: StateUpdateFns[] ): (state: FormGroupState) => FormGroupState; @@ -109,7 +109,7 @@ const groupUpdateFn = updateGroup( const updatedState = groupUpdateFn(state); ``` */ -export function updateGroup( +export function updateGroup( updateFnsArr: StateUpdateFns[], ): (state: FormGroupState) => FormGroupState; @@ -143,7 +143,7 @@ const updatedState = updateGroup( ); ``` */ -export function updateGroup( +export function updateGroup( state: FormGroupState, updateFn: StateUpdateFns, ...updateFnsArr: StateUpdateFns[] @@ -181,7 +181,7 @@ const updatedState = updateGroup( ); ``` */ -export function updateGroup( +export function updateGroup( state: FormGroupState, updateFnsArr: StateUpdateFns[], ): FormGroupState; diff --git a/src/update-function/validate.ts b/src/update-function/validate.ts index b44936d2..0d5ef5a5 100644 --- a/src/update-function/validate.ts +++ b/src/update-function/validate.ts @@ -51,10 +51,11 @@ export function validate( ...rest: ValidationFn[] ) { if (isFormState(stateOrFunctionOrFunctionArray)) { + const state = stateOrFunctionOrFunctionArray as AbstractControlState; const functionArr = Array.isArray(functionOrFunctionArr) ? functionOrFunctionArr : [functionOrFunctionArr!]; const errors = functionArr.concat(...rest) - .reduce((agg, validationFn) => Object.assign(agg, validationFn(stateOrFunctionOrFunctionArray.value)), {} as ValidationErrors); - return formStateReducer(stateOrFunctionOrFunctionArray, new SetErrorsAction(stateOrFunctionOrFunctionArray.id, errors)); + .reduce((agg, validationFn) => Object.assign(agg, validationFn(state.value)), {} as ValidationErrors); + return formStateReducer(stateOrFunctionOrFunctionArray, new SetErrorsAction(state.id, errors)); } const functionOrFunctionArray = stateOrFunctionOrFunctionArray as ValidationFn | ValidationFn[];