javascript - Visual Studio Code 智能感知和 JavaScript ES5

标签 javascript intellisense visual-studio-code typescript-typings

在 Visual Studio Code (VSCode) 中,我正在使用 JavaScript ES5 旧应用程序。我注意到 IntelliSense 不适用于我安装的所有类型。 Intellisense 适用于全局类型,但不适用于外部类型?由于这是遗留代码,我宁愿不更改源 .js 文件以使 Intellisense 正常工作。

用于全局类型的智能感知,例如 Angular 和 jquery,似乎有效。但是,外部类型的 IntelliSense 不起作用。

在这里你可以看到我安装了四种类型。 Angular 和 jQuery 作为全局变量安装。 LoDash 和 Ramda 作为外部安装。我创建了一个 jsconfig.json 文件;它是空的。通过使用 jsconfig.json 文件,IntelliSense 适用于 Angular 和 Jquery,但不适用于 LoDash 和 Ramda。

VSCode Typings

在接下来的两张图中,您可以看到 Intellisense 适用于 Angular 和 jQuery。

VSCode Typings with Angular

VSCode Typings with jQuery

现在,我正在使用 LoDash,但 IntelliSense 不起作用。

VSCode Typings with LoDash

如果我导入 LoDash 库,则 IntelliSense 可以工作。由于代码是旧版 ES5 JavaScript,并且 ES5 不支持导入,因此使用导入并不是一个可行的选择。

VSCode Typings with LoDash and imports

一个好的测试是让 IntelliSense 为 LoDash 工作。我想输入“_”。并让 VSCode 显示 LoDash 属性和方法的列表,而无需在源代码中包含任何其他代码。

有谁知道如何解决这个问题吗?如果是这样,请提供对您有用的方法。

资源

酒吧开发

最佳答案

official VS Code JS Intellisense documentation 中所写,

If you are using Visual Studio Code 1.8+, you can alternately explicitly list packages to acquire typings for in your jsconfig.json.

"typeAcquisition": {
    "include": [
        "lodash"
    ]
}

Now when you require or import lodash, Visual Studio Code will use the automatically downloaded typings files for the library to provide rich Intellisense. Most common JavaScript libraries have typings available.

关于javascript - Visual Studio Code 智能感知和 JavaScript ES5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38081094/

相关文章:

javascript - 在 WebStorm 中为 node_modules 启用代码完成

javascript - 如何在 Visual Studio 代码中调试异步/等待?

python - 配置 Visual Studio Code 以在 Windows 上的 bash 中运行 Python

visual-studio-code - 选择在 VS Code 中搜索期间要忽略的文件夹

javascript - 如何使用 JQuery 检查光标是否悬停在元素上

javascript - 不知道如何解决(Php和Javascript之间)

javascript - 在类方法 Javascript 中引用类变量

python - VS Code、Python、Intellisense 和导入模块为

javascript - jquery 操作 html

javascript - Visual Studio 2010 JavaScript Intellisense 在 "function"中大写 F