Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

tslint

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.

like image 380
Brandon Avatar asked Sep 27 '17 14:09

Brandon


2 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.

like image 148
Brandon Avatar answered Nov 05 '22 01:11

Brandon


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'],
        },
    ],
},
like image 1
jestho Avatar answered Nov 05 '22 01:11

jestho