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 :
node .\node_modules\gulp\bin\gulp.js someTSBuildTaskName –color | Select-String -NotMatch "TS2365" | Select-String -NotMatch "TS2345" | Out-File "grepts.txt"
PS script – output just to console (just drop the last part after pipe) :
node .\node_modules\gulp\bin\gulp.js someTSBuildTaskName –color | Select-String -NotMatch "TS2365" | Select-String -NotMatch "TS2345"
PS: I am calling here the gulp task without gulp installed with -g flag (global) so you can just call
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 :
Mapping Script :
String fileName = matcher.group(1)
String line = matcher.group(2)
String category = matcher.group(3)
String message = matcher.group(4)
return new Warning(fileName, Integer.parseInt(line), "TS Error", category, message);
and plug this into your build pipeline.