tslint how to disable error “someVariable is declared but its value is never read ”

≡放荡痞女 提交于 2019-12-03 22:03:56

Any parameter name starting with _ is exempt from the check. Use _myVariable instead of myvariable to remove this warning.

Fist question:

Edit the file:tsconfig.json, adding/modifying key "noUnusedLocals": false.

You'll need to restart the server.

Second question:

If it is a tslint error; VS Code shows, in the error message, the rule that's been applied.

Identifier 'doc' is never reassigned; use 'const' instead of 'let'. (prefer-const)

The prefer-const rule in this case.

Add this line just before the line which causes the error:

  /* tslint:disable:no-unused-variable */

You will no longer receive the tslint error message.

This is a better solution than turning off the error for you whole codebase in tslint.conf because then it wouldn't catch variables that really aren't used.

I am using typescript": "2.9.1" with tslint": "^5.10.0.

I was getting tons of error such as

Property 'logger' is declared but its value is never read.

Also, I observed that I was getting a warning when running ng-lint

$> ng lint
no-unused-variable is deprecated. Since TypeScript 2.9. Please use the built-in compiler checks instead.

So, I removed the no-unused-variable rule fromt tslint.json - and that seems to solve the problem for me.

Another way to avoid this is to create a get-method for every variable you have, like this:

get variablename():variabletype{return this.variablename;}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!