Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to colorize the errors in tsc output?

When developing a typescript project I run the compiler in watch mode:

tsc --watch

Yet when an error appears, I find it hard to discern in the output as I have plain formatted text:

error output of tsc: <code>src/core/SnowWhite/Cruise/SnowWhiteCruiseClient.ts(10,52): error TS2304: Cannot find name 'favfav'.</code>

Often time I don't even read it, as there are multiple outputs from previous runs.

I currently am trying to ease my pain by grepping for errors in order to mark those line in red:

tsc -w | egrep --color '.*error.*|$'

yet that feels hackish. Is there a more easy way to get errors printed out nicely in typescript?

like image 591
k0pernikus Avatar asked Dec 19 '16 12:12

k0pernikus


1 Answers

TypeScript supports multiple compiler options, and one of them is pretty:

Stylize errors and messages using color and context.

Alas, it defaults to false so you have to enable it in your .tsconfig:

{
    "compilerOptions": {
        "pretty": true
    }
}

Then you get colors and more context information:

Screenshot of tsc with pretty enabled to provide colors and more context on errors

like image 139
k0pernikus Avatar answered Oct 05 '22 23:10

k0pernikus