typescript 安装 angular 1.5 类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37825672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:34:12  来源:igfitidea点击:

Installing angular 1.5 typings

angularjstypescripttypescript-typingsangularjs-1.5

提问by Aaron Beall

Update 3/26/2017

2017/3/26 更新

I now use npm install @types/angularwith TypeScript 2.0 and the experience so far has been much smootherthan typingswas.

我现在使用npm install @types/angularTypeScript 2.0,到目前为止的体验比以前流畅得多typings

Original

原来的

I have an Angular 1.5 project using ES6 modules and Webpack, which is very similar to this starter project.

我有一个使用 ES6 模块和 Webpack 的 Angular 1.5 项目,它与这个 starter project非常相似。

I am attempting to install typingsfor Angular 1.5. I've used tsdin the past, but this is the first time I've tried to use the newer typingsmanager.

我试图安装分型对角1.5。我过去使用tsd过,但这是我第一次尝试使用较新的typings管理器。

When I try typings install angularI get:

当我尝试时,typings install angular我得到:

"Unable to find "angular" ("npm") in the registry."

When I run typings search angularI see a result NAME: angular, SOURCE: dt.

当我运行时,typings search angular我看到了结果NAME: angular, SOURCE: dt

When I try typings install angular dt~angularI get:

当我尝试时,typings install angular dt~angular我得到:

"Attempted to compile "angular" as an external module, but it looks like a global module." 

However when I look at DefinitelyTyped/angular.d.tsI see that although it does declare a global angularvariable, it also declares a module "angular", as many of the DefinitelyTyped definitions do to support UMD.

然而,当我查看absoluteTyped/angular.d.ts 时,我发现虽然它确实声明了一个全局angular变量,但它也声明了一个 module "angular",正如许多绝对类型定义所做的那样,以支持 UMD。

How can I get this to work with typings? Or should I just stick with tsd?

我怎样才能让它与打字机一起工作?还是我应该坚持tsd

采纳答案by basarat

I see that although it does declare a global angular variable, it also declares a module "angular"

我看到虽然它确实声明了一个全局角度变量,但它也声明了一个模块“角度”

The whole file is still global. i.e. there can be only one declare module "angular". Hence you still need to global flag (typings install dt~angular --global)

整个文件仍然是全局的。即只能有一个declare module "angular"。因此你仍然需要全局标志 ( typings install dt~angular --global)

回答by KimchiMan

with TypeScript 2.0, you can make package.jsonfile like this:

使用 TypeScript 2.0,你可以制作这样的package.json文件:

{
    ...
    "dependencies": {
        "@types/angular": "^1.5.6",
    }
    ...
}

Now, you can just run npm install!

现在,你可以跑了npm install