スポンサーリンク
目次
consoleを使うと警告が出る
TypeScriptを使っている際に、ログ出力のためにconsole.error()
などを使うと以下のような警告が出るようになります。
1 2 3 4 5 6 7 8 |
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
に以下を追加すれば使用しても警告が出なくなります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
{ "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] // 追加 } } |
とても簡単ですね!
本日のオススメ商品
Anker 大容量モバイルバッテリー
Anker モバイルバッテリー搭載 USB急速充電器
日清 カップヌードル
GoPro HERO8 Black
烏龍茶 2L x 9本
マンハッタンポーテージ カジュアルバッグ
終わりに
以上のように、原因さえ分かれば簡単に警告を消す事が出来ました。
お困りの際はぜひこのやり方を試してみてください♪