简体   繁体   English

在 Visual Studio 中将打字稿错误报告为警告,并且不会使构建失败

[英]Report typescript errors as warnings in Visual Studio and don't fail the build

I want to typecheck existing javascript code.我想对现有的 javascript 代码进行类型检查。 To that end, I have specified the following tsconfig.为此,我指定了以下 tsconfig. Running tsc results in a couple of hundred errors, which show up in Visual Studio when I do a build.运行tsc导致数百个错误,这些错误会在我进行构建时显示在 Visual Studio 中。 However those errors now also fail the build.然而,这些错误现在也使构建失败。 As the code is currently functioning, I want to postpone resolving those errors.由于代码目前正在运行,我想推迟解决这些错误。 I want the errors to be reported as warnings, such that the build will continue and we can gradually improve the javascript.我希望将错误报告为警告,以便构建将继续,我们可以逐步改进 javascript。

// tsconfig.json
{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "checkJs": true,
    "allowJs": true,
    "noEmit": true
  }
}
//csproj (abbreviated)
<Project>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
  <PropertyGroup>
    <TypeScriptToolsVersion>3.6</TypeScriptToolsVersion>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
</Project>
...

Example msbuild output:示例 msbuild 输出:

...
file.js:153:33 - error TS2769: No overload matches this call.
========== Build: 14 succeeded, 1 failed, 23 up-to-date, 0 skipped ==========

As far as I recall, msbuild's exec command searches the output for the word error , and if found will emit a build error.据我所知,msbuild 的exec命令在输出中搜索error一词,如果找到将发出构建错误。

Which it seems that this linter *.targets file is doing.这个 linter *.targets 文件似乎正在做。 And seems to be corroborated here:似乎在这里得到证实:
Does the MSBuild Exec task search STDOUT for the string "error"? MSBuild Exec 任务是否在 STDOUT 中搜索字符串“error”?

But really:但真的:
If you want to postpone fixing those errors, I see no choice but to simply rip out your linter from your *.csproj files completely.如果您想推迟修复这些错误,我别无选择,只能从您的 *.csproj 文件中完全删除您的 linter。 I mean why put in the linter only to ignore it and defer your technical debt?我的意思是为什么放入 linter 只是为了忽略它并推迟你的技术债务?

In that case I'd simply put take that code you shared, and pull it out of the .csproj file and put it into a separate, standalone msbuild file and run it separately.在这种情况下,我只需将您共享的代码从 .csproj 文件中提取出来,然后将其放入单独的独立 msbuild 文件中,然后单独运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 构建时的Visual Studio 2015 CTP TypeScript错误 - Visual Studio 2015 CTP TypeScript Errors on Build 打字稿:为什么 Visual Studio 代码不报告与命令行 tsc 相同的错误? - Typescript: Why doesn't visual studio code report the same errors that the command line tsc does? 在 Visual Studio Code 中使用 TypeScript 时,如何将 TS 警告配置为显示为错误? - When using TypeScript in Visual Studio Code, how do I configure TS warnings to be shown as errors? Visual Studio不显示typescript错误 - Visual Studio not showing typescript errors Visual Studio / typescript 打字错误 - visual studio / typescript typings errors 如何在并发症错误/警告上使包裹/婴儿/打字稿处理失败? - How to fail parcel/babel/typescript proccess on complication errors/warnings? Visual Studio 2017 Webform中的Typescript无法生成js文件 - typescript in visual studio 2017 webform doesn't build js file 在Visual Studio 2012中构建TypeScript - TypeScript Build in visual studio 2012 Visual Studio Online Build中的TypeScript - TypeScript in Visual Studio Online Build Visual Studio TypeScript设置在部署时失败 - Visual Studio TypeScript settings fail on deployment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM