TSlint: "let" and "const" trigger the forbidden keyword "var" error

I am running TSLint (v5.3.2) with my typescript project. I get the Forbidden keyword 'var', instead of 'let' or 'const' instead , but I do not use 'var', and this indicates my use of 'let' or 'const'.

For example, here is the codeFrame format of the error to show that I am using 'const' and not 'var':

Forbidden 'var' keyword, use 'let' or 'const' instead (no-var-keyword)
  58 |         .map((response) => {
  59 |           // update the login status
> 60 |           const tokensValid = response['isvalid'] === true;
     |                ^
  61 |           if (tokensValid) {
  62 |             this.loggedIn$.next(true);
  63 |             return true;

So far, I have not been able to figure out why I am getting this error. Any ideas?

Thank.

+6
source share
4 answers

, 1.1.0. 1.0.1 tslint . , , .

+2

webpack, tslint-loader awesome-typescript-loader. , ():

module: {
    rules: [
        {
            test: /\.tsx?$/,
            enforce: 'pre', // this little bugger
            loader: 'tslint-loader',
        },
        {
            test: /\.tsx?$/,
            use: ['awesome-typescript-loader'],
        },
    ],
},
+1

This is apparently a mistake with TSlint itself. I would recommend that you disable this rule in the configuration tslint.jsonand see if it works.

{
    "rules": {
        "no-var-keyword": true
    }
}

If it doesn't work, it could be a bug with your IDE or something else. Hope this helps you.

0
source

Adding npx to the command helped me:

npx tslint -c tslint.json -p tsconfig.json

(Use of yarn 1.16.0)

0
source

Source: https://habr.com/ru/post/1686488/


All Articles