我正在将AngularJS应用程序升级到Angular,并且创建了一个使用TypeScript 2.6.2的AngularJS / Angular混合项目。 (它本质上是通过使用SystemJS进行模块加载,通过Angular Bootstrap方法加载AngularJS来工作的)。
当我使用以下命令从Windows命令行运行节点安装的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
我不得不卸载并重新加载项目几次,之间进行保存,直到VS2015项目属性被Visual Studio识别为已禁用。关闭并重新打开Visual Studio,如果出现提示,则保存对项目的任何更改,可能会达到相同的效果:
现在,该项目无需使用即可构建:
<TypeScriptCompile Include="**\*.ts" />
而且我在解决方案中不再有任何错误。
(我还使用Visual Studio中的Nuget软件包管理器安装和卸载了“ TypeScript编译器”,尽管我不确定这是否有效果,因为我已经从https://www.microsoft.com/en-us/download/details.aspx?id=48593安装了VS2015的TypeScript构建工具)
关于javascript - 在.csproj中包含所有TypeScript文件后出现Typescript错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48161302/