简体   繁体   English

Visual Studio Code ES7 / JS Intellisense

[英]Visual Studio Code ES7/JS Intellisense

I'm trying to use Visual Studio Code to edit files in a react starter kit project. 我正在尝试使用Visual Studio Code编辑react starter Kit项目中的文件。 The React project uses Babel for trans-piling, and so it has only .js files instead of .ts files. React项目使用Babel进行转码,因此它只有.js文件而不是.ts文件。 I would like VS Code to provide proper intellisense for these files... including new async/await Javascript keywords . 我希望VS Code为这些文件提供正确的智能感知... 包括新的异步/等待Javascript关键字

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. 到目前为止,如果我将文件的扩展名从.js重命名为.ts ,我只能使intellisense正常工作,但我不想转换整个项目只是为了适合我的个人工具选择。

Is there a way to make VS Code treat .js files as if they were .ts files...simply for the sake of ES7 intellisense? 有没有办法让VS代码处理.js文件好像它们是.ts文件...只是为了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: 我还尝试添加一个如下所示的tsconfig.json文件:

{
  "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. 我希望这会欺骗Typescript来确认.js文件,但没有运气。

Ultimately I would just like to have ES7 intellisense in VS Code. 最后我想在VS Code中使用ES7 intellisense。 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. 就此而言,如果VS代码的替代方案提供了相当于ES7 Javascript的智能感知,我也有兴趣知道这一点。

Visual Studio Code Visual Studio代码

  • VSCode doesn't support filesGlob . VSCode不支持filesGlob Its an atom-ts only thing at the moment. 它目前只是一个原子。
  • To use .js files you need enable allowJs 要使用.js文件,您需要启用allowJs

Solution

tsconfig.json : 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 注意:目标es6为您提供所有最新功能(包括任何es7) http://json.schemastore.org/tsconfig

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM