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
There are two type of variables and you can do it in two ways
varsIgnorePattern
no-unused-vars: ["error", { "argsIgnorePattern": "^_" }]
no-unused-vars: ["error", { "varsIgnorePattern": "^_" }]
Both these rule in eslint will ignore any function arguments and variables that starts with _ sign respectively
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.
Extend the tsconfig.json with dev.tsconfig.json
And run the command tsc -p ./dev.tsconfig.json
This will deisable the unused variable and unused parameter in development
Inside dev.tsconfig.json:
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noUnusedLocals": false,
"noUnusedParameters": false,
}
}
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.
Any parameter name starting with _ is exempt from the check. Use _myVariable
instead of myvariable
to remove this warning.
First turn off noUnusedLocals
in tsconfig.json:
{
"compilerOptions": {
"noUnusedLocals": false,
}
}
Then fix eslint rules in .eslintrc.js
:
module.exports = {
rules: {
'no-unused-vars': ['warn', { 'varsIgnorePattern': '^_' }],
'@typescript-eslint/no-unused-vars': ['warn', { 'varsIgnorePattern': '^_' }],
},
};
And If using @typescript-eslint/naming-convention
rule should add leadingUnderscore: 'allow'
, For example, if you are using Airbnb config:
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'variable',
format: ['camelCase', 'PascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allow',
},
{
selector: 'function',
format: ['camelCase', 'PascalCase'],
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
],