Reputation: 1691
I have three arrays called,
let averageReport: any = [1, 2, 3, 4, 5]
let maleData: Array<any> = [];
let femaleData: Array<any> = [];
I loop through average report and push values to maleData and femaleData. I declared the array types as any but still typescript is complaining that "Argument of type 'number' is not assignable to parameter of type 'string'" There are similar questions with the same question title as this but this is not same as those questions.
here is the code on stackblitz
code,
ngOnInit() {
let averageReport: any = [1, 2, 3, 4, 5]
let maleData: Array<any> = [];
let femaleData: Array<any> = [];
let dateNow = new Date();
let startDate = new Date(dateNow.getTime() - 20000);
averageReport
.map(
x => {
if (x === 1) {
femaleData.push(
{
x: parseInt(startDate.getTime() / 1000), // here is the propblem
y: x.result
})
}
if (x === 2) {
maleData.push(
{
x: parseInt(startDate.getTime() / 1000),
y: x.result
})
}
}
)
}
Upvotes: 1
Views: 825
Reputation: 3236
Have a try with this: I changed "Array" to "any[]", changed .map to for-of, and parseInt to Math.round
ngOnInit() {
let averageReport: any = [1, 2, 3, 4, 5]
let maleData: any[] = [];
let femaleData: any[] = [];
let dateNow = new Date();
let startDate = new Date(dateNow.getTime() - 20000);
for(let report of averageReport) {
if (report === 1) {
femaleData.push(
{
x: Math.round(startDate.getTime() / 1000), // here is the propblem
y: report.result
})
}
if (report === 2) {
maleData.push(
{
x: Math.round(startDate.getTime() / 1000),
y: report.result
})
}
}
}
Upvotes: 1