TSlint: 'let' and 'const' triggers forbidden 'var' keyword error

Viewed 3659

I'm running TSLint (v5.3.2) with my typescript project. I'm getting Forbidden 'var' keyword, use 'let' or 'const' instead but I'm not using 'var' and it points to my use of 'let' or 'const'.

For example, here's a codeFrame format of the error to show I'm 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 haven't been able to figure out why I'm getting this error. Any ideas?

Thanks.

4 Answers

Turns out to be an issue with yarn 1.1.0. Downgraded to yarn 1.0.1 and tslint started passing again. Have not determine exactly what changed between the two versions that caused the issue.

Just encountered this problem with webpack, tslint-loader and awesome-typescript-loader. I solved it by doing this (simplified):

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

This seems to be an error with TSlint itself. I would recommend you to deactivate this rule on the tslint.json config and see if it works.

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

In case it does not work it might be an error with your IDE or something. Hope this helps you out.

Adding npx to the command did the trick for me:

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

(Using Yarn 1.16.0)

Related