I am in the process of upgrading an Angular project from version 10 to 17. While upgrading to Angular 14, I encountered several errors throughout the project. One of the issues arises from the following function:
getPeriodOfNoticeList(unitData) {
if (this.mandateData.mandateGeneral.periodOfNotice && this.mandateData.mandateGeneral.periodOfNotice.length > 0) {
this.MandateDetailsPeriodOfNotice.controls = [];
this.mandateData.mandateGeneral.periodOfNotice.forEach(elem => {
let obj = this.getMandateDetailsPeriodOfNotice();
obj.patchValue(elem);
this.MandateDetailsPeriodOfNotice.push(obj);
});
}
}
The line causing the error is:
obj.patchValue(elem);
I receive the following error message:
Argument of type 'MandateDetailsPeriodOfNotice' is not assignable to parameter of type 'Partial<{ ID: string; MandateID: string; NoticePeriod: number; ObjectTypeID: string; ObjectTypeName: string; CategoryName: string; OperationFlag: string; }>'.
Types of property 'NoticePeriod' are incompatible.
Type 'string' is not assignable to type 'number'
It seems this error is related to stricter type checking in the newer version of Angular. The NoticePeriod
property is expected to be a number
, but it is currently a string
.
How can I resolve this type incompatibility issue?
Any guidance on how to properly handle this type mismatch would be greatly appreciated.