【问题标题】:Visual Studio Code ES7/JS IntellisenseVisual Studio Code ES7/JS 智能感知
【发布时间】:2016-04-12 10:10:36
【问题描述】:

我正在尝试使用 Visual Studio Code 编辑 react starter kit 项目中的文件。 React 项目使用 Babel 进行转桩,因此它只有 .js 文件而不是 .ts 文件。我希望 VS Code 为这些文件提供适当的智能感知...包括新的 async/await Javascript 关键字

到目前为止,如果我将文件的扩展名从 .js 重命名为 .ts,我只能让智能感知正常工作,但我不想仅仅为了适应我的个人工具选择而转换整个项目。

有没有办法让 VS Code 将 .js 文件视为 .ts 文件...仅仅是为了 ES7 智能感知?我发现了一个thread of discussion about this,但我不确定今天有哪些可用的选项。我还尝试添加一个如下所示的 tsconfig.json 文件:

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

我希望这会欺骗 Typescript 承认 .js 文件,但没有运气。

最终我只想在 VS Code 中使用 ES7 智能感知。如果有完全不同的方法来实现这一点,那也将受到欢迎。就此而言,如果有替代 VS Code 的替代方法可以为 ES7 Javascript 提供智能感知功能,我也很想知道。

【问题讨论】:

  • @epascarello:酷!有没有办法为Visual Studio Code 激活它?或者它只是Visual Studio 的一个选项?另外,在Visual Studio 的上下文中,看起来我需要创建一个.njsproj.jsproj 文件才能开始...

标签: javascript typescript ecmascript-6 visual-studio-code ecmascript-2016


【解决方案1】:

Visual Studio 代码

  • VSCode 不支持filesGlob。它是目前唯一的原子。
  • 要使用.js 文件,您需要启用allowJs

解决方案

tsconfig.json:

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

注意:Target es6 为您提供所有最新功能(包括任何 es7 功能)http://json.schemastore.org/tsconfig

【讨论】:

    猜你喜欢
    • 2021-01-07
    • 2018-02-24
    • 2016-02-27
    • 2021-06-10
    • 2016-06-27
    • 2021-03-03
    • 2018-09-05
    • 2017-05-28
    • 1970-01-01
    相关资源
    最近更新 更多