Uniphonic
Uniphonic

Reputation: 875

VS Code Intellisense for JS files without *.d.ts

In VS Code, how do I include js files for Intellisense/autocomplete, without compiling them in Angular, and without creating definition *.d.ts files for each of them?

I have an Angular 4 (actually Ionic 3 which uses Angular 4) project where I'm trying to use VS Code as an editor, but Intellisense for JavaScript files only seems to work for the current file in focus and not for other JS files in the same project, unless I include the files (which are in the path "www/js/*.js" ) in the compiler options in the tsconfig.json file:

"include": [
    "src/**/*.ts",
    "src/**/*.d.ts",
    "www/js/*.js"
  ],

The problem is, I don't want to include those files in the compile, since they're already referenced in the index.html template. When I compile with them, I get errors. I only want to include them in Intellesense, not compile them. Any way to achieve this, WITHOUT creating *.d.ts files for each of them?

Currently my workaround is to just use a different editor (Adobe Brackets) when editing my js that I don't want compiled, so that I can use the Intellisense of Brackets (which works very well), but I'd prefer to just use VS Code editor for everything if possible.

Thanks in advance!

Upvotes: 2

Views: 1250

Answers (1)

Uniphonic
Uniphonic

Reputation: 875

After more research combined with lots of trial and error, I was able to find that adding a jsconfig.json file to my www folder (it didn't work correctly when I put it in my root folder alongside the tsconfig.json file), with the following contents, then it seemed to at least make Intellisense work between the js files, though I still haven't been able to work from the ts files to the js files. Here is the contents of my jsconfig.json file:

{
   "compilerOptions": {
    "target": "ES5",
    "module": "commonjs",
    "allowSyntheticDefaultImports": true
  },
  "include": [
    "js/*.js"
  ],
  "exclude": [
    "node_modules"
  ]
}

I hope this helps someone else who comes across the same problem.

If anyone finds a way to get the Intellisense to work for the js files, while working in the ts files, please post an answer here. Thanks!

Upvotes: 1

Related Questions