VSCode Angular&打字:没有intellisense

时间:2016-05-05 19:49:15

标签: angularjs typescript intellisense visual-studio-code

我尝试使用angular 1.5.5设置一个新项目,我想为我的代码使用typescript。我使用Visual Studio Code作为我的编码工具 我为我的项目添加了角度的类型:

typings install angular --save --ambient

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

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

提前做好准备! 亚历山大。

4 个答案:

答案 0 :(得分:1)

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

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代表来源:

enter image description here

我认为您必须重新启动 VS代码才能看到效果并具有智能感知功能。

答案 1 :(得分:1)

我自己遇到了一些问题,以下是我采取的步骤。

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

注意项目根目录中的typings文件夹。如果您看不到打字文件夹重新启动VS代码或cmd+shift+p并输入重新加载并选择Reload Window

在根目录中也是typings.json文件,其中包含以下对象。

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

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

再次创建jsconfig.json文件Reload Window后。我打开了app.js文件并获得了angularjs的智能感知。

enter image description here

答案 2 :(得分:0)

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

答案 3 :(得分:-1)

您的文件结构错误:

  1. tsconfig.json应位于您应用的根目录,即AngularApp
  2. 通常,typings.d.ts也在那里。
  3. 移动这两个文件后,请记住更改其中的路径。必须包含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.

相关问题