consoleを使うと警告が出る
TypeScriptを使っている際に、ログ出力のためにconsole.error()などを使うと以下のような警告が出るようになります。
WARNING in /Users/blogenist/Develop/sample/src/App.vue
106:9 Calls to 'console.error' are not allowed.
104 | })
105 | .catch(err => {
> 106 | console.error("Copy Error.", err);
| ^
107 | });
108 | }
これは、TypeScriptの環境ではconsole.error()を使用する事は許可されていないようです。
もちろん、別の記述に変えれば良いのですが使いたい場合はtslint.jsonに一行追加するだけで警告が出なくなるのでご紹介致します。
手順
tslint.jsonに追記
解決方法はとても簡単で、tslint.jsonのrulesに以下を追加すれば使用しても警告が出なくなります。
{
"defaultSeverity": "warning",
"extends": ["tslint:recommended"],
"linterOptions": {
"exclude": ["node_modules/**"]
},
"rules": {
"indent": [true, "spaces", 2],
"interface-name": false,
"no-consecutive-blank-lines": false,
"object-literal-sort-keys": false,
"ordered-imports": false,
"quotemark": [true, "double"],
"trailing-comma": [true, "never"],
"curly": true,
"arrow-parens": [2, "always"],
"no-console": [false] // 追加
}
}
とても簡単ですね!
終わりに
以上のように、原因さえ分かれば簡単に警告を消す事が出来ました。
お困りの際はぜひこのやり方を試してみてください♪
