javascript - 将所有 TypeScript 文件包含在 .csproj 中后出现 Typescript 错误

标签 javascript angular typescript visual-studio-2015

我正在将 AngularJS 应用程序升级到 Angular,并且创建了一个使用 TypeScript 2.6.2 的混合 AngularJS/Angular 项目。 (它本质上是通过 Angular 引导方法加载 AngularJS,使用 SystemJS 进行模块加载)。

当我使用以下命令从 Windows 命令行运行安装了 Node 的 TypeScript 时,它编译时不会出现错误:

npm run tsc

当我第一次尝试在 Visual Studio 2015 中构建项目时,TypeScript 没有转换为 JavaScript,因此我尝试将以下内容添加到 .csproj 文件中(之前没有包含 TypeScript 文件的说明):

<ItemGroup>
    <TypeScriptCompile Include="**\*.ts" />

现在我收到以下构建错误:

enter image description here

我的项目结构是这样的:

enter image description here

还有我的 tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": false,
    "suppressImplicitAnyIndexErrors": true,
    "noStrictGenericChecks": true
  },
  "include": [ "**/*.ts" ]
}

可能会发生什么情况以及我可以做什么才能成功构建项目?

最佳答案

我发现我的项目未能通过 Visual Studio 成功构建的原因是我需要在解决方案中包含 tsconfig.json 文件。这会导致 Visual Studio 忽略 .csproj 文件中的 TypeScript 配置并使用 tsconfig.json

我必须卸载并重新加载项目几次,并在中间进行保存,直到 Visual Studio 识别出 VS2015 项目属性已被禁用。关闭并重新打开 Visual Studio,根据提示保存对项目的任何更改,可能会实现相同的效果:

enter image description here

该项目现在无需使用即可构建:

<TypeScriptCompile Include="**\*.ts" />

我的解决方案中不再有任何错误。

(我还使用 Visual Studio 中的 Nuget 包管理器安装和卸载了“TypeScript 编译器”,尽管我不确定这是否有任何影响,因为我已经从 https://www.microsoft.com/en-us/download/details.aspx?id=48593 安装了 VS2015 的 TypeScript 构建工具)

关于javascript - 将所有 TypeScript 文件包含在 .csproj 中后出现 Typescript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48161302/

相关文章:

javascript - 解析云代码-修改所有PFUsers

angular - ionic 4 tabs starter - href ="/tabs/(contact:contact)"做什么

angular - ngx-toastr - 通用类型 'ɵɵComponentDeclaration' 需要 7 到 8 个类型参数

angular - 使用 getter 和 setter 拦截@Input 变化

typescript - JestJS TypeScript : mockImplementation Does not Exist on Type

javascript - 将未定义常量与 Angular 一起使用

javascript - iOS webView 的 Angular 问题

javascript - Angular 2 中的异步等待

angular - 为什么 Angular 的英雄之旅 http 错误处理程序接受任何类型的参数?

javascript - 选中的复选框背景不起作用