In my code, I have defined an interface called DateArray:
export interface DateArray {
year : number;
}
Within my component, I am declaring a new variable named dateArray like this:
private dateArray: DateArray = {
year: null
};
Then, I am assigning a value to dateArray.year in the following manner:
this.dateArray.year = this.megaData[0][3];
What puzzles me is that regardless of whether the value of this.megaData[0][3]
is a string, number, or array, it gets assigned to this.dateArray.year
without any issues.
When I try to assign a string to dateArray.year directly like so:
this.dateArray.year = "A"
I encounter an error stating "can't assign string to number". However, if the value of this.megaData[0][3]
happens to be "A"
, then strangely no error occurs. And when I print out the result of:
this.dateArray.year = this.megaData[0][3];
console.log("this.dateArray.year);
The output is simply A
.
At the moment, this.megaData
is only defined as <any>
. Could this possibly be causing the issue?