Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

TypeError: Cannot read property 'flags' of undefined (no-unused-variable) #3001

Closed
danielweck opened this issue Jul 6, 2017 · 11 comments · Fixed by #3058
Closed

TypeError: Cannot read property 'flags' of undefined (no-unused-variable) #3001

danielweck opened this issue Jul 6, 2017 · 11 comments · Fixed by #3058

Comments

@danielweck
Copy link

"TypeError: Cannot read property 'flags' of undefined" with no-unused-variable rule.

TypeScript 2.4.1
https://unpkg.com/typescript@2.4.1/

TSlint 5.5.0
https://unpkg.com/tslint@5.5.0/

Running TSlint via CLI (package.json script with tslint --type-check --project "./tsconfig.json" -c "./tslint.json" "./src/**/*.ts")

TypeError: Cannot read property 'flags' of undefined
    at Object.getCheckFlags (/PROJECT/node_modules/typescript/lib/typescript.js:10137:22)
    at getTypeOfSymbol (/PROJECT/node_modules/typescript/lib/typescript.js:30957:20)
    at getTypeOfNode (/PROJECT/node_modules/typescript/lib/typescript.js:47329:24)
    at Object.getTypeAtLocation (/PROJECT/node_modules/typescript/lib/typescript.js:26823:31)
    at getImplicitType (/PROJECT/node_modules/tslint/lib/rules/noUnusedVariableRule.js:269:24)
    at cb (/PROJECT/node_modules/tslint/lib/rules/noUnusedVariableRule.js:259:20)
    at visitEachNode (/PROJECT/node_modules/typescript/lib/typescript.js:15956:30)
    at Object.forEachChild (/PROJECT/node_modules/typescript/lib/typescript.js:16143:24)
    at cb (/PROJECT/node_modules/tslint/lib/rules/noUnusedVariableRule.js:264:19)
    at visitNode (/PROJECT/node_modules/typescript/lib/typescript.js:15944:20)

tslint.json configuration:

{
  "extends": "tslint:recommended",
  "rules": {
    "no-floating-promises": true,
    "promise-function-async": true,
    "await-promise": true,
    "no-unused-variable": true,
    "no-unused-expression": true,
    "variable-name": [
      true,
      "ban-keywords",
      "check-format",
      "allow-leading-underscore",
      "allow-trailing-underscore",
      "allow-pascal-case"
    ],
    "ordered-imports": [
      true,
      {
        "import-sources-order": "case-insensitive",
        "named-imports-order": "lowercase-last"
      }
    ],
    "no-console": [
      false
    ],
    "interface-name": [
      false
    ]
  },
  "jsRules": {
    "ordered-imports": [
      true,
      {
        "import-sources-order": "case-insensitive",
        "named-imports-order": "case-insensitive"
      }
    ]
  },
  "rulesDirectory": []
}
@danielweck
Copy link
Author

Related?
#2649

@victornoel
Copy link

I have been having the same problem for some months now too.
I personally don't want to use the typescript options that achieve the same result as no-unused-variable (mainly because when you are in dev mode, you don't really care if there is unused imports or stuffs like that…).

@victornoel
Copy link

@danielweck I don't think it is related, #2649 seems to appear only on windows and I have the same exact problem as you on linux :)

@victornoel
Copy link

See also #2876

@karfau
Copy link

karfau commented Jul 18, 2017

I have the exact same stacktrace in our (private) project,

From what I have read, the only difference I can spot between this error and #2876 is that it also occurs when there is no unused variable.
Wich means the stacktrace is part of the output on every build for us.

@Hotell
Copy link

Hotell commented Jul 19, 2017

we have same issue as well

tslint 5.5.0
typescript 2.2.2
env: OSX

@westy92
Copy link

westy92 commented Jul 19, 2017

I have the same issue as well.

tslint: 5.5.0
TypeScript: 2.4.1
OS: Ubuntu 16.04.2

https://travis-ci.org/westy92/html-pdf-chrome/jobs/255121048#L1299

@ochanje210
Copy link

same issue here

tslint: 5.5.0
TypeScript: 2.4.2
OS: OSX

@ochanje210
Copy link

I have submitted PR for this: microsoft/TypeScript#17367

@DanielRosenwasser
Copy link
Contributor

Does anyone have a simple codebase to reproduce the issue as a regression test?

@ajafff
Copy link
Contributor

ajafff commented Aug 1, 2017

@DanielRosenwasser #2876 contains a minimal reproduction for this issue

adidahiya pushed a commit that referenced this issue Aug 2, 2017
Avoid typescript crash when trying to get type of destructured variable declaration.
Also avoid walking the AST multiple times when `--declaration` is not enabled. That should result in better performance and fewer false negatives.

[bugfix] `no-unused-variable` fixed crash when using destructuring
Fixes: #2876
Fixes: #3001
@adidahiya adidahiya added this to the TSLint v5.6 milestone Aug 2, 2017
HyphnKnight pushed a commit to HyphnKnight/tslint that referenced this issue Apr 9, 2018
Avoid typescript crash when trying to get type of destructured variable declaration.
Also avoid walking the AST multiple times when `--declaration` is not enabled. That should result in better performance and fewer false negatives.

[bugfix] `no-unused-variable` fixed crash when using destructuring
Fixes: palantir#2876
Fixes: palantir#3001
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants