iobroker-javascript-vs-code-extension icon indicating copy to clipboard operation
iobroker-javascript-vs-code-extension copied to clipboard

Intellisense shows non existent errors (double created variables)

Open gsicilia82 opened this issue 2 years ago • 4 comments

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 image

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

gsicilia82 avatar Jan 04 '23 13:01 gsicilia82

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.

nokxs avatar Jan 14 '23 14:01 nokxs

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?

gsicilia82 avatar Jan 18 '23 16:01 gsicilia82

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.

nokxs avatar Mar 08 '23 21:03 nokxs

It would be really appreciated. At the moment I don't like to use vscode cause of this intellisense issue.

Thanks for your effort.

gsicilia82 avatar Mar 08 '23 21:03 gsicilia82