NEWS
[Gelöst] TypeScript: Zugriff iobJS.StateObject in forEach()
-
Ich bekomme einen Fehler wenn ich iobJS.StateObject innerhalb eines forEach() verwende.
getShellyDevicesAll().forEach(shelly => { let objId = shelly.getBaseState() + ".online"; let obj = getObject(objId) as iobJS.StateObject; });
...führt noch zu einem Fehler:
javascript.1 (487) script.js.common.Test: TypeScript compilation failed: let obj = getObject(objId) as iobJS.StateObject; ^ ERROR: Conversion of type '{ common: { [x: string]: any; [x: number]: any; }; type: "meta" | "config" | "user" | "state" | "instance" | "adapter" | "channel" | "folder" | "device" | "script" | "enum" | "group" | "host" | "chart"; ... 8 more ...; encryptedNative: string[]; }' to type 'StateObject' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first. Types of property 'common' are incompatible. Type '{ [x: string]: any; [x: number]: any; }' is missing the following properties from type 'StateCommon': read, write, role, name
@AlCalzone Möchte nicht nerven, aber fragen, ob Du hier noch eine Idee hast? (Das ist ein Folgeticket - da anderes Thema - zu https://forum.iobroker.net/topic/57264/gelöst-typescript-kompilierfehler-setobject)
-
Ok da muss ich wirklich nochmal ran. Schön ist das nicht...
@uwe72 sagte in TypeScript: Zugriff iobJS.StateObject innerhalb forEach():
getObject(objId) as iobJS.StateObject
ersetzen durch:
getObject(objId) as unknown as iobJS.StateObject
-
@alcalzone said in TypeScript: Zugriff iobJS.StateObject innerhalb forEach():
getObject(objId) as unknown as iobJS.StateObject
Hat funktioniert. Danke dir von Herzen!!
getShellyDevicesAll().forEach(shelly => { let objId = shelly.getBaseState() + ".online"; let obj = getObject(objId) as unknown as iobJS.StateObject; if (!obj.common.custom) { obj.common.custom = {}; } obj.common.custom['statistics.0'] = { "enabled": true, "count": false, "sumCount": false, "timeCount": true, "fiveMin": false, "impUnitPerImpulse": 1, "impUnit": "", "avg": false, "minmax": false, "sumDelta": false, "sumIgnoreMinus": false, "groupFactor": 1, "logName": "online_script" }; setObject(objId, obj); });