I get an error as below
Argument of type 'any' is not assignable to parameter of type 'never'.
And the error is at alarm[key]
Here is my code:
import { Injectable } from '@angular/core';
import alarmData from '../../mockData/alarmdData.json';
interface IAlarm {
createdTime: string;
station: string;
deviceID: string;
category: string;
alarmValue: number;
alarmType: string;
status: string;
startTime: string;
endTime: string;
handleState: string;
}
@Injectable({
providedIn: 'root',
})
export class AlarmDataService {
setColumnData(key: string, array: number[] | string[]): void {
alarmData.forEach((alarm: IAlarm) => array.push(alarm[key]));
}
logData() {
console.log(alarmData);
}
}
My json file content is below:
[
{
"createdTime": "2022/03/24 18:00",
"station": "testStation",
"deviceID": "S1001",
"category": "SO2",
"alarmValue": 33,
"alarmType": "SO2 limit",
"status": "alarm",
"startTime": "2022/03/24 18:00",
"endTime": "2022/03/24 19:00",
"handleState": "handled"
},
{
"createdTime": "2022/03/24 19:00",
"station": "test1Station",
"deviceID": "S1002",
"category": "NO",
"alarmValue": 33,
"alarmType": "NO limit",
"status": "alarm",
"startTime": "2022/03/24 20:00",
"endTime": "2022/03/24 21:00",
"handleState": "handled"
}
]
Why I get this hint 'Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'IAlarm'. No index signature with a parameter of type 'string' was found on type 'IAlarm'.'.
What should I do to debug my code? Thank you for helping me in advance.
I have tried to change the array to 'any' but it still does not work.