Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 419
PatS Avatar asked Oct 18 '22 03:10

PatS


People also ask

How do I disable Tslint line?

You can suppress TSLint rules for the current file and even for the current line. IntelliJ IDEA automatically generates disable comments in the format /* tslint:disable:<rule name> or // tslint:disable-next-line:<rule name> and places them on top of the file or above the current line respectively.

How do I disable Tslint to a file?

In addition to global configuration, you may also enable/disable linting for a subset of lint rules within a file with the following comment rule flags: /* tslint:disable */ - Disable all rules for the rest of the file. /* tslint:enable */ - Enable all rules for the rest of the file.

How do I use console log in TypeScript?

Use the console.In the console. log() method, we can output a message to the web console. The message may be a single string or multiple JavaScript objects.


1 Answers

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
    }
}
like image 272
Christian Ivicevic Avatar answered Oct 20 '22 16:10

Christian Ivicevic