Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

tslint

I'm using tslint, and got the error.

'myVariable' is declared but its value is never read.

I went to the website that documents the rules https://palantir.github.io/tslint/rules/ and searched for the string is declared but its value is never read but didn't find that text. While I can and did look for settings that might be tied to this error, it shouldn't be a guessing game.

What is the configuration change needed to suppress/stop this error?

Just as importantly, when I get an error in tslint that says "this happened" how can I find what setting is used to configure or change the tslint behavior on how to handle that error?

I also did a search on the website (google search I used was)

site:palantir.github.io  is declared but its value is never read 

but a direct hit did not appear, so the answer might be on the palantir.github.io website but I just didn't (yet) find it.

How do others find the tslint variable/configuration settings that change to suppress a particular error?

Please refrain from suggesting I comment out the code that is causing the problem. I'm looking for an answer to my more general question as well as to the specific question. Thank you.

like image 472
PatS Avatar asked Apr 24 '18 22:04

PatS


3 Answers

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

like image 193
Rachit Rawat Avatar answered Nov 18 '22 15:11

Rachit Rawat


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.

like image 24
Roger Avatar answered Nov 18 '22 14:11

Roger


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.

like image 43
edwin Avatar answered Nov 18 '22 15:11

edwin