在 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。
在接下来的两张图中,您可以看到 Intellisense 适用于 Angular 和 jQuery。
现在,我正在使用 LoDash,但 IntelliSense 不起作用。
如果我导入 LoDash 库,则 IntelliSense 可以工作。由于代码是旧版 ES5 JavaScript,并且 ES5 不支持导入,因此使用导入并不是一个可行的选择。
一个好的测试是让 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/