I am dealing with the following code snippet:
spear.ts:
export class Spears {
constructor(
id: string = null,
transaction_id: string = null,
spear_id: number = null,
delivery_date: any = null,
delivery_time: any = null,
...
) {}
}
Later on, I am using that class in my component.ts class and assigning it data fetched from the backend.
spear.component.ts:
export class CpCoorPenerimaanSpearDetailComponent implements OnInit {
spear = new Spears();
spearForm = new Spears();
constructor() { }
ngOnInit() {
this._spears.getSpearDetail().subscribe(
res => {
this.spear = res.data;
this.spearForm = res.data;
}
err => console.log(err);
);
}
}
Every time I try to access the value of the object, an error message appears stating that the property does not exist on type Object. For instance, when I attempt to log the 'spear_id' property right after executing spearForm = res.data
, the message displayed is:
Property 'spear_id' does not exist on type 'Spears'.
I have been struggling with this issue for 5 hours now. I searched for similar questions and found suggestions to change the type of the property to 'any'. Even just trying to log the 'spear_id', which is of type number, results in a 'property does not exist' message.
What confuses me the most is that sometimes the error message disappears, but then reappears unexpectedly. Can anyone provide assistance with this?