When using eslint's "restrict template expressions", how do you log a boolean variable? Also, if I wanted to disable the restriction for a line, how to do it?
const flag:boolean = true;
console.log("flag=" + flag);
console.log(`flag=${flag}`);
both generate this error:
error Invalid type "boolean | undefined" of template literal expression @typescript-eslint/restrict-template-expressions
In your .eslintrc:
module.exports = {
"rules": {
"@typescript-eslint/restrict-template-expressions": "error"
}
};
Ref: https://typescript-eslint.io/rules/restrict-template-expressions/
You can suppress the error for a line like this:
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
console.log(`flag=${flag}`);
Just a little suggestion, if you are using typescript, maybe you should use const or let instead of var
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