From a6c4093d3553c4d0f95e496678e2a8f1cab0b9de Mon Sep 17 00:00:00 2001 From: Dan Percic Date: Wed, 9 Mar 2022 11:20:07 +0200 Subject: [PATCH] fix typing --- src/lib/form/base-form.component.ts | 2 +- src/lib/utils/functions.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/form/base-form.component.ts b/src/lib/form/base-form.component.ts index 72eae14..eefd3ed 100644 --- a/src/lib/form/base-form.component.ts +++ b/src/lib/form/base-form.component.ts @@ -5,7 +5,7 @@ import { AutoUnsubscribe, hasFormChanged } from '../utils'; @Directive() export abstract class BaseFormComponent extends AutoUnsubscribe { form!: FormGroup; - initialFormValue; + initialFormValue!: Record; get changed(): boolean { return hasFormChanged(this.form, this.initialFormValue); diff --git a/src/lib/utils/functions.ts b/src/lib/utils/functions.ts index 4c5b234..6c36967 100644 --- a/src/lib/utils/functions.ts +++ b/src/lib/utils/functions.ts @@ -34,11 +34,11 @@ export function trackByFactory() { return (index: number, item: T): string => item.id; } -export function hasFormChanged(form: FormGroup, initialFormValue): boolean { +export function hasFormChanged(form: FormGroup, initialFormValue: Record): boolean { if (form && initialFormValue) { for (const key of Object.keys(form.getRawValue())) { const initialValue = initialFormValue[key]; - const updatedValue = form.get(key).value; + const updatedValue = form.get(key)?.value; if (initialValue == null && updatedValue != null) { const updatedValueType = typeof updatedValue;