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.
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.
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.
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.
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With