我刚开始使用带有 typescript 的 create-react-app
create-react-app my-app --scripts-version=react-scripts-ts
并且默认的 tslint.json 配置不允许 console.log()。
我如何(现在)启用console.log?
相关文档位于 https://palantir.github.io/tslint/rules/no-console/ 。但他们没有说把这条线放在哪里:
"no-console": [true, "log", "error"]
我搜索并找到了这个 tslint.json 配置文件语法,所以我尝试了这个:
"rules": {
"no-console": [true, "warning"]
}
试图获取只是警告的日志消息。但这没有用。
我已经注释掉了我拥有的几行 console.log() 行,但我希望将来能够做到这一点。
原文由 PatS 发布,翻译遵循 CC BY-SA 4.0 许可协议
在您调用
console.log
之前的行中添加// tslint:disable-next-line:no-console
--- 以防止仅出现一次错误消息。如果您想完全禁用该规则,请将以下内容添加到您的
tslint.json
(很可能在您的根文件夹中):