Skip to content
  • Home
  • Aktuell
  • Tags
  • 0 Ungelesen 0
  • Kategorien
  • Unreplied
  • Beliebt
  • GitHub
  • Docu
  • Hilfe
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Standard: (Kein Skin)
  • Kein Skin
Einklappen
ioBroker Logo

Community Forum

donate donate
  1. ioBroker Community Home
  2. Deutsch
  3. Skripten / Logik
  4. JavaScript
  5. [Gelöst] TypeScript: Zugriff iobJS.StateObject in forEach()

NEWS

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    22
    1
    1.1k

  • UPDATE 31.10.: Amazon Alexa - ioBroker Skill läuft aus ?
    apollon77A
    apollon77
    48
    3
    9.1k

  • Monatsrückblick – September 2025
    BluefoxB
    Bluefox
    14
    1
    2.4k

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

Geplant Angeheftet Gesperrt Verschoben JavaScript
3 Beiträge 2 Kommentatoren 308 Aufrufe 2 Watching
  • Älteste zuerst
  • Neuste zuerst
  • Meiste Stimmen
Antworten
  • In einem neuen Thema antworten
Anmelden zum Antworten
Dieses Thema wurde gelöscht. Nur Nutzer mit entsprechenden Rechten können es sehen.
  • U Offline
    U Offline
    uwe72
    schrieb am zuletzt editiert von uwe72
    #1

    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 Antwort Letzte Antwort
    0
    • AlCalzoneA Offline
      AlCalzoneA Offline
      AlCalzone
      Developer
      schrieb am zuletzt editiert von
      #2

      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
      

      Warum `sudo` böse ist: https://forum.iobroker.net/post/17109

      U 1 Antwort Letzte Antwort
      0
      • AlCalzoneA AlCalzone

        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 Offline
        U Offline
        uwe72
        schrieb am zuletzt editiert von
        #3

        @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 Antwort Letzte Antwort
        0
        Antworten
        • In einem neuen Thema antworten
        Anmelden zum Antworten
        • Älteste zuerst
        • Neuste zuerst
        • Meiste Stimmen


        Support us

        ioBroker
        Community Adapters
        Donate

        794

        Online

        32.5k

        Benutzer

        81.6k

        Themen

        1.3m

        Beiträge
        Community
        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
        ioBroker Community 2014-2025
        logo
        • Anmelden

        • Du hast noch kein Konto? Registrieren

        • Anmelden oder registrieren, um zu suchen
        • Erster Beitrag
          Letzter Beitrag
        0
        • Home
        • Aktuell
        • Tags
        • Ungelesen 0
        • Kategorien
        • Unreplied
        • Beliebt
        • GitHub
        • Docu
        • Hilfe