6

I'm trying to use Visual Studio Code to edit files in a react starter kit project. The React project uses Babel for trans-piling, and so it has only .js files instead of .ts files. I would like VS Code to provide proper intellisense for these files...including new async/await Javascript keywords.

So far I can only get intellisense to work properly if I rename the extension of files from .js to .ts, but I don't want to convert the whole project just to suit my personal tool choices.

Is there a way to make VS Code treat .js files as if they were .ts files...simply for the sake of ES7 intellisense? I spotted a thread of discussion about this, but I'm not sure what options are available today. I also tried adding a tsconfig.json file that looks like this:

{
  "compilerOptions": {
    "target": "es6"  //An "es7" option is not yet legal
  },
  "filesGlob": [
    "./**/*.js",
    "!./node_modules/**/*.js"
  ]  
}

I hoped this would trick Typescript into acknowledging .js files, but no luck.

Ultimately I would just like to have ES7 intellisense in VS Code. If there is an entirely different way to achieve this, that would also be welcome. For that matter, if there is an alternative to VS Code that provides the equivalent of intellisense for ES7 Javascript, I'm interested to know about that too.

Brent Arias
  • 29,277
  • 40
  • 133
  • 234
  • https://github.com/Microsoft/nodejstools/wiki/ES6-IntelliSense-Preview-in-NTVS-1.1 – epascarello Jan 07 '16 at 21:06
  • @epascarello: Cool! Is there a way to activate this for `Visual Studio Code`? Or is it only an option for `Visual Studio`? Also, in the context of `Visual Studio`, it looks like I need to create a `.njsproj` or `.jsproj` file before I can get started... – Brent Arias Jan 07 '16 at 21:11

1 Answers1

0

Visual Studio Code

  • VSCode doesn't support filesGlob. Its an atom-ts only thing at the moment.
  • To use .js files you need enable allowJs

Solution

tsconfig.json:

{
  "compilerOptions": {
    "target": "ES6",
    "allowJs": true,
  },
  exclude: ["node_modules"]
}

Note: Target es6 gives you all the latest features (including any es7 ones) http://json.schemastore.org/tsconfig

basarat
  • 261,912
  • 58
  • 460
  • 511