This is my code
sumDevices() {
let onlineDevicesArray = [];
let offlineDevicesArray = [];
for(let group of this.groups[this.selectedDeviceSource.id]){
for(let device of group.devices){
if(device.onlineState == "Online"){
onlineDevicesArray.push(device.onlineState);
this.onlineDevices = onlineDevicesArray.length;}
else{
offlineDevicesArray.push(device.onlineState);
this.offlineDevices = offlineDevicesArray.length;
}
}
}
}
It gives an error on device.onlineState, but the function does work.
TS2339:Property 'onlineState' does not exist on type 'never'.
Can anyone explain to me why its giving me this error?
You need to provide type for arrays, by default it is "never". Something like this should work.
let onlineDevicesArray:number[] = [];
let offlineDevicesArray:any[] = [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With