如何在 Visual Studio Code 中为 Angular.Js 和 Javascript 设置智能感知,而无需在每个 js 文件上添加 TypeScript 文件引用 [英] How to set intellisense for Angular.Js and Javascript in Visual Studio Code without adding TypeScript file reference on every js file

查看:20
本文介绍了如何在 Visual Studio Code 中为 Angular.Js 和 Javascript 设置智能感知,而无需在每个 js 文件上添加 TypeScript 文件引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 VS Code 的新手,想用它来开发 AngularJs 应用程序.但是,我遇到了在所有 JS 文件顶部添加参考链接的问题.

I am new to VS Code and want to use it for the development of an AngularJs app. However, I am having the problem of adding a reference link on the top of all JS files.

像这样.

 /// <reference path="path/to/typings/tsd.d.ts" />

有什么替代方法吗?

推荐答案

默认情况下,所有在 Visual Studio Code 中打开的 JavaScript 文件都被视为独立的单元.如果要为整个项目启用 IntelliSense,请记住将 jsconfig.json 文件放在项目的根目录下.

By default, all JavaScript files opened in Visual Studio Code are treated as independent units. If you want to enable IntelliSense for the whole project remember to place the jsconfig.json file at the root of your project.

下面是一个 jsconfig.json 文件,它将 JavaScript 目标定义为 ES6 并排除 node_modules 文件夹.

Below is a jsconfig.json file which defines the JavaScript target to be ES6 and excludes the node_modules folder.

{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "allowSyntheticDefaultImports": true
  },
  "exclude": [
    "node_modules"
  ]
}

您可以通过使用来自 DefinitelyTyped 存储库.使用 Typings 管理器可以轻松管理打字.

You can get IntelliSense for AngularJS library through the use of type definition .d.ts files from DefinitelyTyped repository. The typings are easily managed using Typings manager.

要安装 Typings 管理器,请执行 npm install typings --global.这将安装类型管理器作为您的全局 npm 模块.然后你可以安装 AngularJS Definitions 使用 typings install dt~angular --全局 命令.这将安装和持久化来自绝对类型存储库的定义作为全局定义.

To install Typings manager execute npm install typings --global. This will install typings manager as your global npm module. Then you can install AngularJS Definitions using typings install dt~angular --global command. This will install and persist definitions from DefinitelyTyped repository as global definitions.

您可以使用 typings search angular 列出可用的定义.

You can list available definitions using typings search angular.

现在,您的项目中的所有文件都可以使用 IntelliSense,而无需添加 /// 引用.

Now you'll have IntelliSense available for all files in your project without the need of adding /// reference.

您可以在 VS Code 手册中找到更多信息.

You can find more in the VS Code manual.

希望这会有所帮助!

这篇关于如何在 Visual Studio Code 中为 Angular.Js 和 Javascript 设置智能感知,而无需在每个 js 文件上添加 TypeScript 文件引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆