I just want to share this short poor man’s fix when migrating TypeScript to filter out some particular errors in TypeScript build.
Why the hell you (might) need it?
So what would be the common use case , why to bother mask/mute errors on build? Compile is the first test our code need to undergo, like first pass of “unit tests”.
- error TS2365 Operator ‘>=’ cannot be applied to types ‘string’ and ‘number’.
- error TS2365 Operator ‘==’ cannot be applied to types ‘string’ and ‘number’.
- error TS2345 Argument of type ‘number’ is not assignable to parameter of type ‘string’.
We are not alone in this, more ppl write about it here :
and also here https://github.com/Microsoft/TypeScript/issues/11051
So the solutions vary from custom branch of TypeScript as such to stupid grep on the command line output. And since I am on Windows 10 (my dev box) , I chose to stick with PowerShell so this is snippet that should do the job.
Lets say we want to mute TS2365 and TS2345 errors and your TS build gulp task has name someTSBuildTaskName.
PS script – output to some file :
<br /> node .\node_modules\gulp\bin\gulp.js someTSBuildTaskName --color | Select-String -NotMatch "TS2365" | Select-String -NotMatch "TS2345" | Out-File "grepts.txt"<br />
PS script – output just to console (just drop the last part after pipe) :
<br /> node .\node_modules\gulp\bin\gulp.js someTSBuildTaskName --color | Select-String -NotMatch "TS2365" | Select-String -NotMatch "TS2345"<br />
PS: I am calling here the gulp task without gulp installed with -g flag (global) so you can just call
<br /> gulp someTSBuildTaskName<br />
with globally installed gulp and you are also good to go.
Found any better solution? Pls let us know in comments! :)
AD: you can also use this console log parser on Jenkins:
Regular Expression :
<br /> ([\w\\\.]+)\((\d+),\d+\):\s+\w+\s+((?!TS2365|TS2345)\w+):\s+(.*)$<br />
Mapping Script :
<br /> import hudson.plugins.warnings.parser.Warning</p> <p>String fileName = matcher.group(1)<br /> String line = matcher.group(2)<br /> String category = matcher.group(3)<br /> String message = matcher.group(4)</p> <p>return new Warning(fileName, Integer.parseInt(line), "TS Error", category, message);<br />
and plug this into your build pipeline.