Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. [Gelöst] TypeScript: Zugriff iobJS.StateObject in forEach()

    NEWS

    • ioBroker goes Matter ... Matter Adapter in Stable

    • 15. 05. Wartungsarbeiten am ioBroker Forum

    • Monatsrückblick - April 2025

    [Gelöst] TypeScript: Zugriff iobJS.StateObject in forEach()

    This topic has been deleted. Only users with topic management privileges can see it.
    • U
      uwe72 last edited by uwe72

      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
      

      5277e2b9-5388-40ce-bcc7-29b6d792f61f-image.png

      @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)

      1 Reply Last reply Reply Quote 0
      • AlCalzone
        AlCalzone Developer last edited by

        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
        
        U 1 Reply Last reply Reply Quote 0
        • U
          uwe72 @AlCalzone last edited by

          @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);
          });
          
          1 Reply Last reply Reply Quote 0
          • First post
            Last post

          Support us

          ioBroker
          Community Adapters
          Donate

          812
          Online

          31.6k
          Users

          79.5k
          Topics

          1.3m
          Posts

          2
          3
          225
          Loading More Posts
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes
          Reply
          • Reply as topic
          Log in to reply
          Community
          Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
          The ioBroker Community 2014-2023
          logo