【问题标题】:Angular2 typescript in Asp.Net Mvc 4, getting startedAsp.Net Mvc 4 中的 Angular2 打字稿,入门
【发布时间】:2016-04-10 21:01:03
【问题描述】:

我不确定如何在 typescript、Visual Studio 2015 for Asp.Net MVC 4 中开始使用 Angular2

我有一个包含这个的打字稿文件

import { bootstrap } from 'angular2/platform/browser';

然后我使用 nuget 获取 angular2.TypeScript.DefinitelyTyped

现在编译给了我很多错误,例如

Build: Cannot find module 'angular2/platform/browser'

还有几千个这样的错误

Build: Duplicate identifier 'SetterFn'

这大概是因为存在很多版本的角度 ts 文件

我在网络参考 tsconfig.json 和 Asp.Net Mvc 5/Core 上找到的所有答案

从哪里开始?

【问题讨论】:

  • 使用 npm 和来自 npm 的类型来管理肯定类型的类型。 Nuget 缺乏管理它们的类型。 Nuget 类型总是落后于原始 github 版本
  • 到目前为止,我已经设法摆脱了不使用 npm 的情况,如果我真的走这条路,不会还有 angular2、alpha26、28、30 等的多个版本。如何typescript 知道使用哪一个吗?

标签: typescript angular


【解决方案1】:

问题是 typings 安装引入了两个版本的类型,所以你会在类型文件夹下看到 browser.d.ts 和 main.d.ts。

当 TypeScript 看到这两者时,您会收到 Duplicate identifier 错误。这是 IMO 混乱的根源,但解决方法是删除其中一个。通过删除文件(和同名文件夹)或在 tsconfig.json 中将其列为 exclude

对于浏览器中的 Angular 等前端项目,我会删除 main.d.ts

tsconfig 排除示例:

{
  "exclude": [
    "typings/main.d.ts",
    "typings/main"
  ]
}

【讨论】:

    猜你喜欢
    • 2016-09-06
    • 1970-01-01
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-06
    • 2016-04-23
    相关资源
    最近更新 更多