TSlint: 'let' and 'const' triggers forbidden 'var' keyword error
Asked Answered
F

4

11

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.

Frontier answered 27/9, 2017 at 14:47 Comment(1)
have you found any solution for thatFiguration
F
2

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.

Frontier answered 28/9, 2017 at 18:24 Comment(2)
yes, this fixed the issue for me as well (had to re-add tslint via the downgraded yarn install), thanks @FrontierMcelroy
I think this is github.com/palantir/tslint/issues/3251 - it seems that yarn 1.1.0 somehow causes tslint-loader to run as a loader when it should be a pre-loader.Tamarisk
C
1

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'],
        },
    ],
},
Complaint answered 28/9, 2017 at 18:17 Comment(0)
H
0

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.

Hendon answered 27/9, 2017 at 14:58 Comment(2)
Setting no-var-keyword rule to false does turn off the check so the error no longer shows up as expected, but then its of course not running the check.Frontier
As i said, it might be an error with TSlint check, because of map. I don't know what workaround could you do to make it work. You might need to open an issue on Github with TSlint directly.Hendon
S
0

Adding npx to the command did the trick for me:

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

(Using Yarn 1.16.0)

Sybilla answered 5/7, 2019 at 19:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.