ioBroker.javascript: Global TS constants/functions are not defined in JS scripts (again)
I have the same problem as described in #687:
I use global files, to store object ids to being able to switch them out in one place and use the constant in all my scripts.
My global files are all Typescript as well as most of my non-global scripts. This worked in version 4.9.8, but does not work since 4.10.1. (I could not check 4.10.0 as iobroker did not want to install this). The most up-to-date version I tested was 5.0.14, which does also show the described behavior.
Steps to reproduce the behavior:
- Have a TypeScript file “Konstanten” in global with a constant, e.g.
const ID_DEV_WZ_Fernbedienung_1_PRESS_SHORT:string = getIdByName("WZ.Fernbedienung:1.PRESS_SHORT", true)[0];
- Add a JavaScript non-global script to any folder and try to use the contstant, e.g.:
on ({id: ID_DEV_WZ_Fernbedienung_1_PRESS_SHORT, change: "any"},
function(){
// do something
}
);
- See error
javascript.0 | 2021-03-14 20:17:44.747 | error | (16554) ReferenceError: ID_DEV_WZ_Fernbedienung_1_PRESS_SHORT is not defined |
---|---|---|---|
javascript.0 | 2021-03-14 20:17:44.747 | error | (16554) ^ |
javascript.0 | 2021-03-14 20:17:44.747 | error | (16554) on({ id: ID_DEV_WZ_Fernbedienung_1_PRESS_SHORT, change: “any” }, function () { |
Expected behavior The constants should be available in non-global scripts.
Versions: Adapter version: 4.10.1 to 5.0.14 ( I tested versions 4.10.1, 4.10.10, 4.11.0, 5.0.14) JS-Controller version: 3.2.16 Node version: v10.22.0 Operating system: linux
Work around The downgrade to 4.9.8 did fix my problem.
See also #726, which might be related.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Comments: 17 (2 by maintainers)
I’m having the same problem, but in TS scripts: global/const.ts
common/test.ts
Results in:
Is this the same issue or should I create a new one? (Or am I doing something wrong?)
Edit: Functions are actually working, but constants/variables are not.
Hey, sorry to bump this. I’ve just upgraded to version 6.1.4 and now my global scripts cannot access each others interfaces, classes and enums anymore.
If there is anything I can do to help resolve this problem, please let me know.
Hi AlCalzone,
thank you for looking into this. According to your hint, I tried to do something else than constants and, thus, I converted the file in a class containing public static variables as I did not want to loose the typing. That works with 5.0.14.
I will try to change this into get accessors, so that the variables cannot be changed, but it is already good enough to work for my use case.
Thanks again!
Stefan
P.S. For everybody who is interested. My constants for my device-ids are now managed inside a class:
Example for usage: