2016-05-05 41 views
1

我尝试设置一个角度为1.5.5的新项目,我想使用打字稿来处理我的代码。我使用Visual Studio Code作为我的编码工具。
我增加了对角的分型到我的项目:VSCode Angular&typings:没有intellisense

typings install angular --save --ambient 

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

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

伟大的thx提前!
亚历山大。

回答

-1

你的文件结构是错误的:

  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.

0

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

1

我猜你一定见过一个错误执行时:

typings install angular --save --ambient 

首先,您必须安装新的TypeScript Definition Manager

npm install typings --global 

,那么你必须在你的项目文件夹中使用这个命令:

typings install dt~angular --global --save 

如在中所解释的。

这个命令应该创建一个文件typings.json应该是这个样子:

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

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

typings search --name angular 

,你会看到dt代表来源:

enter image description here

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

1

我自己遇到了一些问题,这里是我为了使它工作而采取的步骤。

  • 打开终端,运行...
  • npm install typings -g
  • cd ~/root of your project
  • 我只好跑typings install dt~angular --save --global
  • 我在本地安装typings install dt~angular --save

请注意,在该分型文件夹时出错你的项目的根源。如果您无法看到类型重新启动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的intellisense。

enter image description here

相关问题