iobroker-javascript-vs-code-extension
iobroker-javascript-vs-code-extension copied to clipboard
Intellisense shows non existent errors (double created variables)
Describe the bug Intellisense shows error messages if variables with same names are declared in multiple scripts.
To Reproduce Create two scripts with same variable names. Not all double declared variables are shown as an error. I got two copies from same script, but not all variables are marked as double-created.
Expected behavior There should not be errors at all
Screenshots
Version information (please complete the following information):
- Extension version: 1.2.0
- VS Code version: 1.74.2
- ioBroker admin version: 6.3.5
- ioBroker nodejs version: 16.19.0
- ioBroker javascript adapter version: 6.1.4
I know of the issue, but I don't know how to resolve it. The problem appears, because of the include settings in tsconfig.json
. If the include is specified like this
"include": [
"scripts/global/**/*.js",
"scripts/global/**/*.ts",
".iobroker/types/javascript.d.ts"
],
then the compiler does not compile the script at all and all defintions defined in javascript.d.ts
are not found. This leads to squiggles for every iobroker definied function.
My solution for this problem is using an anonymous function in every script, which is directly executed. Example:
(() => {
// Add your code in here
})();
This approach is more like a workarround, but for its a good enough solution.
Unfortunately, I am not a pro about these kind of "deep" topics. Therefore, I cannot help about further workarounds. Maybe, some ioBroker experts could help?
I just found out about Project References in Typescript: https://www.typescriptlang.org/docs/handbook/project-references.html
These might be the solution to the problem, but I'm not sure about it yet. If I find some time I will have a deeper look into the topic.
It would be really appreciated. At the moment I don't like to use vscode cause of this intellisense issue.
Thanks for your effort.