tslint says calls to console.log are not allowed - How do I allow this?

PatS picture PatS · Apr 23, 2018 · Viewed 82.9k times · Source

I just started using create-react-app with typescript

create-react-app my-app --scripts-version=react-scripts-ts

and the default tslint.json configuration does not allow console.log().

How can I (for now) enable console.log?

The docs for this are at https://palantir.github.io/tslint/rules/no-console/. But they don't say where to put this line:

    "no-console": [true, "log", "error"]

I searched and found this tslint.json configuration file syntax, so I tried this:

"rules": {
    "no-console": [true, "warning"]
}

In an attempt to get log messages that would just be warnings. But that didn't work.

I've commented out the few console.log() lines I have but will want to be able to do this in the future.

Answer

Christian Ivicevic picture Christian Ivicevic · Apr 24, 2018

Add // tslint:disable-next-line:no-console in the line right before your calls to console.log to prevent the error message only once.

If you want to disable the rule entirely add the following to your tslint.json (most likely in your root folder):

{
    "rules": {
        "no-console": false
    }
}