Skip to content
  • Home
  • Recent
  • Tags
  • 0 Unread 0
  • Categories
  • Unreplied
  • Popular
  • 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

  • Default (No Skin)
  • No Skin
Collapse
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.2k

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

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

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

Scheduled Pinned Locked Moved JavaScript
3 Posts 2 Posters 309 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    uwe72
    wrote on last edited by 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 Reply Last reply
    0
    • AlCalzoneA Offline
      AlCalzoneA Offline
      AlCalzone
      Developer
      wrote on last edited by
      #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 Reply Last reply
      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
        wrote on last edited by
        #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 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        Support us

        ioBroker
        Community Adapters
        Donate

        772

        Online

        32.5k

        Users

        81.7k

        Topics

        1.3m

        Posts
        Community
        Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen | Einwilligungseinstellungen
        ioBroker Community 2014-2025
        logo
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Home
        • Recent
        • Tags
        • Unread 0
        • Categories
        • Unreplied
        • Popular
        • GitHub
        • Docu
        • Hilfe