我正在将 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" />
现在我收到以下构建错误:
我的项目结构是这样的:
还有我的 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,根据提示保存对项目的任何更改,可能会实现相同的效果:
该项目现在无需使用即可构建:
<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/