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 Kompilierfehler setObject

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    [Gelöst] TypeScript Kompilierfehler setObject

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

      @alcalzone said in TypeScript Kompilierfehler setObject:

      let obj: iobJS.StateObject = getObject(objId);

      Ich habe es nun so:

      const originalDatenpunkt = 'shelly.0.SHPLG2-1#49FE33#1.online';
      let obj: iobJS.StateObject = getObject(originalDatenpunkt);
      

      Bekomme diesen Fehler:

      javascript.1 (486) script.js.common.Berechnungen.Test_Statistics: TypeScript compilation failed: let obj: iobJS.StateObject = getObject(originalDatenpunkt); ^ ERROR: Type '{ common: { [x: string]: any; [x: number]: any; }; type: "state" | "channel" | "folder" | "device"; acl: { object: number; state: number; owner: string; ownerGroup: string; }; _id: string; native: { [x: string]: any; }; enums: { ...; }; from: string; user: string; ts: number; }' is not assignable to type 'StateObject'. Types of property 'type' are incompatible. Type '"state" | "channel" | "folder" | "device"' is not assignable to type '"state"'. Type '"channel"' is not assignable to type '"state"'.
      

      D.h. "obj" wird schon im Editor angemeckert:
      89e5ddda-12cc-4378-abd6-74f2f91520dc-image.png

      OliverIO 1 Reply Last reply Reply Quote 0
      • OliverIO
        OliverIO @uwe72 last edited by

        @uwe72
        Und was steht im iobroker was für ein Typ das Objekt ist?

        U 1 Reply Last reply Reply Quote 0
        • U
          uwe72 @OliverIO last edited by uwe72

          @oliverio

          Da steht das gleiche wie oben als Text gepostet:
          95d7a7d4-8749-4b44-a5ec-1fadf9b163d9-image.png

          javascript.1 (486) script.js.common.Berechnungen.Test_Statistics: TypeScript compilation failed: let obj: iobJS.StateObject = getObject(originalDatenpunkt); ^ ERROR: Type '{ common: { [x: string]: any; [x: number]: any; }; type: "state" | "channel" | "folder" | "device"; acl: { object: number; state: number; owner: string; ownerGroup: string; }; _id: string; native: { [x: string]: any; }; enums: { ...; }; from: string; user: string; ts: number; }' is not assignable to type 'StateObject'. Types of property 'type' are incompatible. Type '"state" | "channel" | "folder" | "device"' is not assignable to type '"state"'. Type '"channel"' is not assignable to type '"state"'.
          
          1 Reply Last reply Reply Quote 0
          • OliverIO
            OliverIO last edited by OliverIO

            @uwe72
            ich denke das in der Ansicht des Objektbaums bei Typ
            channel dran steht.
            Auf Typ channel kannst du kein typ state setzen., da channel kein attribut common.custom besitzt
            oder es ist umgekehrt, das kann ich nicht so richtig rauslesen

            @uwe72 sagte in TypeScript Kompilierfehler setObject:

            Type '"channel"' is not assignable to type '"state"'.

            warum willst du unbedingt in custom was reinschreiben? ganz davon abgesehen, das es schon gehen muss, aber wenn du eine objektstruktur in einem datenpunkt ablegen willst, dann würde ich einfach mit
            getState und setState arbeiten und das Objekt dort einfach mit JSON.stringify und JSON.parse schreiben und lesen.

            und was mir noch aufgefallen ist:
            statistics.0 ist kein eigener datenpunkt
            das erste richtige objekt in der hierarchie ist
            statistics.0.save und
            statistics.0.temp

            statistics.0 sieht zwar so aus, existiert für sich aber nicht als eigenständiges objekt
            dies ist erkennbar, das im objektbaum bei typ nix dran steht.

            U haus-automatisierung 2 Replies Last reply Reply Quote 0
            • U
              uwe72 @OliverIO last edited by

              @oliverio Ich möchte ja programmatisch für einen Datenpunkt den Statistic-Adapter aktivieren.

              Habe ein Array mit allen Devices (ca. 200-250). So kann ich generisch wie gesagt für alle Devices den StatisticAdapter aktivieren.

              1 Reply Last reply Reply Quote 0
              • U
                uwe72 @AlCalzone last edited by

                @alcalzone Siehe zuvor. Hättest Du mir noch einen Tipp? Grüße aus Brasilien. Uwe

                AlCalzone 1 Reply Last reply Reply Quote 0
                • haus-automatisierung
                  haus-automatisierung Developer Most Active @OliverIO last edited by haus-automatisierung

                  @oliverio sagte in TypeScript Kompilierfehler setObject:

                  statistics.0 sieht zwar so aus, existiert für sich aber nicht als eigenständiges objekt
                  dies ist erkennbar, das im objektbaum bei typ nix dran steht.

                  Das ist normal und auch richtig so. Bei einigen Adaptern wird das als Objekt für den File-Meta-Storage angelegt (z.B. vis). Aber das ist ganz selten und hat mit dem Problem nichts zu tun.

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

                    @uwe72 Ok dann anders:

                    const originalDatenpunkt = 'shelly.0.SHPLG2-1#49FE33#1.online';
                    let obj = getObject(originalDatenpunkt) as iobJS.StateObject;
                    

                    Der Unterschied zur vorherigen Variante ist dass du TS jetzt sagst: "Ich bin mir sicher, das ist ein StateObject". Das andere hat bedeutet: "obj ist ein State, lese mir da das Objekt xyz rein" (was nicht garantiert ein StateObject ist)

                    U 2 Replies Last reply Reply Quote 0
                    • U
                      uwe72 @AlCalzone last edited by uwe72

                      @alcalzone Perfekt, danke dir! Bin wirklich sehr dankbar nun eine funktionierende programmatische Lösung zu haben (für das "Aktivieren" vom Statistikadapter, o.ä.) Hat nun funktioniert:

                      const objId = 'shelly.0.SHPLG2-1#49FE33#1.online';
                      let obj = getObject(objId) 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_trockner"
                      };
                       
                      setObject(objId, obj);
                      
                      1 Reply Last reply Reply Quote 1
                      • U
                        uwe72 @AlCalzone last edited by uwe72

                        Bitte diesen Kommentar löschen, habe ein neues Ticket aufgemacht:
                        https://forum.iobroker.net/topic/57367/typescript-zugriff-iobjs-stateobject-innerhalb-foreach

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        665
                        Online

                        31.8k
                        Users

                        80.0k
                        Topics

                        1.3m
                        Posts

                        6
                        19
                        794
                        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