VSCode Angular & 打字:没有智能感知

VSCode Angular & typings: no intellisense

我尝试使用 angular 1.5.5 建立一个新项目,我想在我的代码中使用打字稿。我使用 Visual Studio 代码作为我的编码工具。
我将 angular 的类型添加到我的项目中:

typings install angular --save --ambient

我添加了一个 typings.d.ts 文件和一个 tsconfig.json 文件,但我没有智能感知我添加的任何 .ts 文件...

不知道我做错了什么?有人能帮我吗? 我尝试设置小项目来重现问题:download link

提前致谢!
亚历山大.

获得智能感知的一种方法是在打字稿文件的顶部添加 ///<reference path="../typings.d.ts" />。添加定义时,请确保将它们添加到 typings.d.ts 文件。

你的文件结构有误:

  1. tsconfig.json 应该在您应用程序的根目录中,即 AngularApp
  2. 通常,typings.d.ts也在那里。

移动这两个文件后,记得更改里面的路径。必须包含ts文件。

//tsconfig.json
{
//...
  "files":[  
    "typings.d.ts",
    "public/app/app.ts"
  ]
}

//typings.d.ts
/// <reference path="typings/browser.d.ts" />

If you want to download.

我猜你一定看到执行时出错了:

typings install angular --save --ambient

首先你必须安装新的 TypeScript Definition Manager:

npm install typings --global

那么您必须在您的项目文件夹中使用此命令:

typings install dt~angular --global --save

quick start 中所述。

此命令应创建一个文件 typings.json,该文件应如下所示:

{
  "globalDependencies": {
    "angular": "registry:dt/angular#1.5.0+20160517064839"
  }
}

如果您想知道 dt 前缀是什么,您可以 运行:

typings search --name angular

你会看到 dt 代表来源:

我认为你必须重新启动 VS Code 才能看到效果并具有智能感知。

我自己 运行 遇到了一些问题,以下是我为使它起作用所采取的步骤。

  • 打开终端并运行...
  • npm install typings -g
  • cd ~/root of your project
  • 我有一个错误运行宁typings install dt~angular --save --global
  • 我在本地安装typings install dt~angular --save

注意项目根目录中的 typings 文件夹。如果看不到 typings 文件夹,请重新启动 VS Code 或 cmd+shift+p 并键入 reload 并选择 Reload Window.

在根目录中还有一个包含以下对象的 typings.json 文件。

{
  "dependencies": {
    "angular": "registry:dt/angular#1.6.0+20170223151516"
  }
}

在项目的根目录中创建一个 empty jsconfig.json

创建 jsconfig.json 文件后,我再次 Reload Window。我打开 app.js 文件并获得 angularjs.

的智能感知