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. (SOLVED) Create Alias in TypeScript

NEWS

  • Jahresrückblick 2025 – unser neuer Blogbeitrag ist online! ✨
    BluefoxB
    Bluefox
    17
    1
    2.3k

  • Neuer Blogbeitrag: Monatsrückblick - Dezember 2025 🎄
    BluefoxB
    Bluefox
    13
    1
    960

  • Weihnachtsangebot 2025! 🎄
    BluefoxB
    Bluefox
    25
    1
    2.2k

(SOLVED) Create Alias in TypeScript

Geplant Angeheftet Gesperrt Verschoben JavaScript
9 Beiträge 3 Kommentatoren 887 Aufrufe 3 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

    Hallo, kann mir jemand diese funktionierende JS-Function in TypeScript zu übersetzen? Ich kriege es nicht hin:

    const idAlias = "test12345";
    const idOrigin = "deconz.1.Lights.2.on";
    
    function createAlias(idSrc, idDst, typeAlias) {
       if(!getObject(idDst)) {
          var obj = {};
          obj.type = 'state';
          obj.common = getObject(idSrc).common;
          if(typeAlias) obj.common.type = typeAlias;
          obj.common.alias = {};
          obj.common.alias.id = idSrc;
          setObject(idDst, obj);
       } //else log ("Alias schon vorhanden: " + idDst, 'warn'); 
    }
    
    createAlias(idOrigin, idAlias, 'boolean');
    

    DANKE !!!!

    155c62f9-0220-498c-8278-7733071e2b1d-image.png

    javascript.0 (4416) script.js.common.#RGB#.CreateAliase: TypeScript compilation failed: obj.type = 'state'; ^ ERROR: Property 'type' does not exist on type '{}'. obj.common = getObject(idSrc).common; ^ ERROR: Property 'common' does not exist on type '{}'. obj.common.type = typeAlias; ^ ERROR: Property 'common' does not exist on type '{}'. obj.common.alias = {}; ^ ERROR: Property 'common' does not exist on type '{}'. obj.common.alias.id = idSrc; ^ ERROR: Property 'common' does not exist on type '{}'. setObject(idDst, obj); ^ ERROR: Argument of type '{}' is not assignable to parameter of type '(Omit<StateObject, "acl" | "_id"> & { _id?: string; acl?: StateACL; }) | (Omit<InstanceObject, "acl" | "_id"> & { _id?: string; acl?: ObjectACL; }) | ... 10 more ... | (Omit<...> & { ...; })'. Type '{}' is not assignable to type 'Omit<OtherObject, "acl" | "_id"> & { _id?: string; acl?: ObjectACL; }'. Type '{}' is missing the following properties from type 'Omit<OtherObject, "acl" | "_id">': common, type, native
    
    1 Antwort Letzte Antwort
    0
    • C Offline
      C Offline
      CruziX
      schrieb am zuletzt editiert von CruziX
      #2

      @uwe72

      const idAlias = "test12345";
      const idOrigin = "deconz.1.Lights.2.on";
      
      type TAlias = {
       id: string;
      };
      
      type TCommon = {
       type?: string;
       alias?: TAlias;
      }; 
      
      type TCustomObject ={
       type: string;
       common: TCommon;
      };
      function createAlias(idSrc: string, idDst: string, typeAlias: string) {
         if(!getObject(idDst)) {
            var obj: TCustomObject = {
       type: 'state',
       common: {
      type: '',
      alias: {
      id: ''
      }
      }
      };
            obj.common = getObject(idSrc).common;
            if(typeAlias) obj.common.type = typeAlias;
            obj.common.alias.id = idSrc;
            setObject(idDst, obj);
         } //else log ("Alias schon vorhanden: " + idDst, 'warn'); 
      }
      

      Kurz mitm Handy getippt, vielleicht hilfts ja

      U 1 Antwort Letzte Antwort
      0
      • C CruziX

        @uwe72

        const idAlias = "test12345";
        const idOrigin = "deconz.1.Lights.2.on";
        
        type TAlias = {
         id: string;
        };
        
        type TCommon = {
         type?: string;
         alias?: TAlias;
        }; 
        
        type TCustomObject ={
         type: string;
         common: TCommon;
        };
        function createAlias(idSrc: string, idDst: string, typeAlias: string) {
           if(!getObject(idDst)) {
              var obj: TCustomObject = {
         type: 'state',
         common: {
        type: '',
        alias: {
        id: ''
        }
        }
        };
              obj.common = getObject(idSrc).common;
              if(typeAlias) obj.common.type = typeAlias;
              obj.common.alias.id = idSrc;
              setObject(idDst, obj);
           } //else log ("Alias schon vorhanden: " + idDst, 'warn'); 
        }
        

        Kurz mitm Handy getippt, vielleicht hilfts ja

        U Offline
        U Offline
        uwe72
        schrieb am zuletzt editiert von uwe72
        #3

        @cruzix bin dir so dankbar, dass Du mein Problem angeschaut hast!!

        Leider gibts noch irgendwie ein "Cast-Problem":

        const idAlias = "test12345";
        const idOrigin = "deconz.1.Lights.2.on";
        
        /*{
          "_id": "alias.0.Light.Device_1.WORKING",
          "type": "state",
          "common": {
            "alias": {
              "id": "admin.0.connected"
            },
            "name": "WORKING",
            "role": "indicator.working",
            "type": "boolean"
          },
          "native": {}
        } */     
        
        type TAlias = {
            id: string;
        };
        
        type TCommon = {
            type: string;
            alias: TAlias;
        }; 
        
        type TCustomObject ={
            type: string;
            common: TCommon;
        };
        
        function createAlias(idSrc: string, idDst: string, typeAlias: string) {
            if (!getObject(idDst)) {
                var obj: TCustomObject = {
                    type: '',
                    common: {
                        type: '',
                        alias: {
                            id: ''
                        }
                    }
                };
                obj.type = 'state';
                obj.common = getObject(idSrc).common;
                if(typeAlias) obj.common.type = typeAlias;
                obj.common.alias = {};
                obj.common.alias.id = idSrc;
                
                setObject(idDst, obj);
           }
        }
        

        Den ersten Fehler gibts an dieser Stelle (Zeile 44):
        obj.common = getObject(idSrc).common;

        Type '{ [x: string]: any; [x: number]: any; }' is missing the following properties from type 'TCommon': type, alias(2739)
        (property) common: TCommon
        
        C 1 Antwort Letzte Antwort
        0
        • U uwe72

          @cruzix bin dir so dankbar, dass Du mein Problem angeschaut hast!!

          Leider gibts noch irgendwie ein "Cast-Problem":

          const idAlias = "test12345";
          const idOrigin = "deconz.1.Lights.2.on";
          
          /*{
            "_id": "alias.0.Light.Device_1.WORKING",
            "type": "state",
            "common": {
              "alias": {
                "id": "admin.0.connected"
              },
              "name": "WORKING",
              "role": "indicator.working",
              "type": "boolean"
            },
            "native": {}
          } */     
          
          type TAlias = {
              id: string;
          };
          
          type TCommon = {
              type: string;
              alias: TAlias;
          }; 
          
          type TCustomObject ={
              type: string;
              common: TCommon;
          };
          
          function createAlias(idSrc: string, idDst: string, typeAlias: string) {
              if (!getObject(idDst)) {
                  var obj: TCustomObject = {
                      type: '',
                      common: {
                          type: '',
                          alias: {
                              id: ''
                          }
                      }
                  };
                  obj.type = 'state';
                  obj.common = getObject(idSrc).common;
                  if(typeAlias) obj.common.type = typeAlias;
                  obj.common.alias = {};
                  obj.common.alias.id = idSrc;
                  
                  setObject(idDst, obj);
             }
          }
          

          Den ersten Fehler gibts an dieser Stelle (Zeile 44):
          obj.common = getObject(idSrc).common;

          Type '{ [x: string]: any; [x: number]: any; }' is missing the following properties from type 'TCommon': type, alias(2739)
          (property) common: TCommon
          
          C Offline
          C Offline
          CruziX
          schrieb am zuletzt editiert von CruziX
          #4

          @uwe72 ja, verstehe was das Problem ist, habe in meinem vorherigen Post den Common type mit optionalen Properties ergänzt und die zeile entfernt wo alias mit {} gesetzt wird. Sollte nun klappen

          U 1 Antwort Letzte Antwort
          0
          • C CruziX

            @uwe72 ja, verstehe was das Problem ist, habe in meinem vorherigen Post den Common type mit optionalen Properties ergänzt und die zeile entfernt wo alias mit {} gesetzt wird. Sollte nun klappen

            U Offline
            U Offline
            uwe72
            schrieb am zuletzt editiert von
            #5

            @cruzix

            Danke dir!! Das TypeScript passt nun, irgendwie akzeptiert die setObject Methode noch nicht den Parameter:

            const idAlias = "test12345";
            const idOrigin = "deconz.1.Lights.2.on";
            
            type TAlias = {
             id: string;
            };
            
            type TCommon = {
             type?: string;
             alias?: TAlias;
            }; 
            
            type TCustomObject ={
             type: string;
             common: TCommon;
            };
            
            function createAlias(idSrc: string, idDst: string, typeAlias: string) {
               if(!getObject(idDst)) {
                  var obj: TCustomObject = {
                     type: 'state',
                    common: {
                    type: '',
                    alias: {
                        id: ''
                    }
                }
                };
                    obj.common = getObject(idSrc).common;
                    if(typeAlias) obj.common.type = typeAlias;
                    obj.common.alias.id = idSrc;
                    setObject(idDst, obj);
                } 
            }
            
            //createAlias("deconz.1.Lights.6.on", "alias.0.rgb.Z005.on", "boolean");
            
            Argument of type 'TCustomObject' is not assignable to parameter of type '(Omit<StateObject, "acl" | "_id"> & { _id?: string; acl?: StateACL; }) | (Omit<InstanceObject, "acl" | "_id"> & { _id?: string; acl?: ObjectACL; }) | ... 10 more ... | (Omit<...> & { ...; })'.
              Type 'TCustomObject' is not assignable to type 'Omit<OtherObject, "acl" | "_id"> & { _id?: string; acl?: ObjectACL; }'.
                Property 'native' is missing in type 'TCustomObject' but required in type 'Omit<OtherObject, "acl" | "_id">'.(2345)
            (local var) obj: TCustomObject
            
            U 1 Antwort Letzte Antwort
            0
            • U uwe72

              @cruzix

              Danke dir!! Das TypeScript passt nun, irgendwie akzeptiert die setObject Methode noch nicht den Parameter:

              const idAlias = "test12345";
              const idOrigin = "deconz.1.Lights.2.on";
              
              type TAlias = {
               id: string;
              };
              
              type TCommon = {
               type?: string;
               alias?: TAlias;
              }; 
              
              type TCustomObject ={
               type: string;
               common: TCommon;
              };
              
              function createAlias(idSrc: string, idDst: string, typeAlias: string) {
                 if(!getObject(idDst)) {
                    var obj: TCustomObject = {
                       type: 'state',
                      common: {
                      type: '',
                      alias: {
                          id: ''
                      }
                  }
                  };
                      obj.common = getObject(idSrc).common;
                      if(typeAlias) obj.common.type = typeAlias;
                      obj.common.alias.id = idSrc;
                      setObject(idDst, obj);
                  } 
              }
              
              //createAlias("deconz.1.Lights.6.on", "alias.0.rgb.Z005.on", "boolean");
              
              Argument of type 'TCustomObject' is not assignable to parameter of type '(Omit<StateObject, "acl" | "_id"> & { _id?: string; acl?: StateACL; }) | (Omit<InstanceObject, "acl" | "_id"> & { _id?: string; acl?: ObjectACL; }) | ... 10 more ... | (Omit<...> & { ...; })'.
                Type 'TCustomObject' is not assignable to type 'Omit<OtherObject, "acl" | "_id"> & { _id?: string; acl?: ObjectACL; }'.
                  Property 'native' is missing in type 'TCustomObject' but required in type 'Omit<OtherObject, "acl" | "_id">'.(2345)
              (local var) obj: TCustomObject
              
              U Offline
              U Offline
              uwe72
              schrieb am zuletzt editiert von uwe72
              #6

              Gibts wirklich niemand von den ioBroker-Profis wo dieses Thema lösen können, eigentlich sollte es ja nur eine Kleinigkeit sein?

              Wäre wirklich sehr dankbar!

              LG

              AlCalzoneA 1 Antwort Letzte Antwort
              0
              • U Offline
                U Offline
                uwe72
                schrieb am zuletzt editiert von uwe72
                #7

                OK i think i have a working solution now:

                function createAlias(originalDatenpunkt, aliasDatenpunkt) {
                    setObject(aliasDatenpunkt, {
                        type: 'state',
                            common: {
                            name: getObject(originalDatenpunkt).common.name, 
                            type: getObject(originalDatenpunkt).common.type,  
                            unit: getObject(originalDatenpunkt).common.unit,    
                            read: true,
                            write: true,
                            role: getObject(originalDatenpunkt).common.role,    
                            alias: {
                                id: originalDatenpunkt
                            }
                        },
                        native: {}
                    });
                }
                var originalDatenpunkt = "deconz.1.Lights.2.on";
                var aliasDatenpunkt = "alias.0.test.mytest12_new2_NG";
                createAlias(originalDatenpunkt, aliasDatenpunkt);
                
                1 Antwort Letzte Antwort
                0
                • U uwe72

                  Gibts wirklich niemand von den ioBroker-Profis wo dieses Thema lösen können, eigentlich sollte es ja nur eine Kleinigkeit sein?

                  Wäre wirklich sehr dankbar!

                  LG

                  AlCalzoneA Offline
                  AlCalzoneA Offline
                  AlCalzone
                  Developer
                  schrieb am zuletzt editiert von
                  #8

                  @uwe72 sagte in (SOLVED) Create Alias in TypeScript:

                  eigentlich sollte es ja nur eine Kleinigkeit sein?

                  Ja, stand auch in der von dir zitierten Fehlermeldung :)

                  Property 'native' is missing in type 'TCustomObject' but required [...]

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

                  U 1 Antwort Letzte Antwort
                  0
                  • AlCalzoneA AlCalzone

                    @uwe72 sagte in (SOLVED) Create Alias in TypeScript:

                    eigentlich sollte es ja nur eine Kleinigkeit sein?

                    Ja, stand auch in der von dir zitierten Fehlermeldung :)

                    Property 'native' is missing in type 'TCustomObject' but required [...]

                    U Offline
                    U Offline
                    uwe72
                    schrieb am zuletzt editiert von
                    #9

                    @alcalzone

                    Wie ist deine Meinung dann zu
                    https://forum.iobroker.net/topic/57264/typescript-kompilierfehler-setobject/5

                    Da gibts auch eine Fehlermeldung, für die "ich" eigentlich nicht verantwortlich sein kann?

                    :blush:

                    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

                    643

                    Online

                    32.6k

                    Benutzer

                    82.2k

                    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