Skip to content

[no-unnecessary-type-assertion] "Cannot read property 'declarations' of undefined" in decorator call #532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
G-Rath opened this issue May 15, 2019 · 0 comments · Fixed by #537
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@G-Rath
Copy link
Contributor

G-Rath commented May 15, 2019

Repro

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "tsconfig.json",
    "ecmaVersion": 2015,
    "sourceType": "module"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "extends": [
    "plugin:@typescript-eslint/recommended"
  ],
  "rules": {
    "@typescript-eslint/no-unnecessary-type-assertion": "error"
  }
}
class Mx {
  @a(b!)
  private prop = 1;
}

Here is a repo

PS C:\Users\G-Rath\workspace\projects-personal\js-bugs> eslint --ext ".ts" index.ts --debug
  eslint:cli CLI args: [ '--ext', '.ts', 'index.ts', '--debug' ] +0ms
  eslint:cli Running on files +11ms
  eslint:glob-utils Creating list of files to process. +0ms
  eslint:ignored-paths baseDir = "C:\\Users\\G-Rath\\workspace\\projects-personal\\js-bugs" +0ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/node_modules/*"
  eslint:ignored-paths   cooked   = "/node_modules/*" +3ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "/bower_components/*"
  eslint:ignored-paths   cooked   = "/bower_components/*" +1ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = ".*"
  eslint:ignored-paths   cooked   = ".*" +2ms
  eslint:ignored-paths addPatternRelativeToCwd:
  eslint:ignored-paths   original = "!../"
  eslint:ignored-paths   cooked   = "!../" +1ms
  eslint:ignored-paths Looking for ignore file in C:\Users\G-Rath\workspace\projects-personal\js-bugs +0ms
  eslint:ignored-paths Could not find ignore file in cwd +2ms
  eslint:ignored-paths contains: +3ms
  eslint:ignored-paths   target = "C:\\Users\\G-Rath\\workspace\\projects-personal\\js-bugs\\index.ts" +1ms
  eslint:ignored-paths   result = false +2ms
  eslint:ignored-paths contains: +1ms
  eslint:ignored-paths   target = "C:\\Users\\G-Rath\\workspace\\projects-personal\\js-bugs\\index.ts" +3ms
  eslint:ignored-paths   result = false +4ms
  eslint:cli-engine Processing C:\Users\G-Rath\workspace\projects-personal\js-bugs\index.ts +0ms
  eslint:cli-engine Linting C:\Users\G-Rath\workspace\projects-personal\js-bugs\index.ts +2ms
  eslint:config Constructing config file hierarchy for C:\Users\G-Rath\workspace\projects-personal\js-bugs +0ms
  eslint:config Using .eslintrc and package.json files +1ms
  eslint:config Loading C:\Users\G-Rath\workspace\projects-personal\js-bugs\.eslintrc +6ms
  eslint:config-file Loading config file: C:\Users\G-Rath\workspace\projects-personal\js-bugs\.eslintrc +0ms
  eslint:plugins Loaded plugin @typescript-eslint (@typescript-eslint/eslint-plugin@1.9.0) (from C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\@typescript-eslint\eslint-plugin\dist\index.js) +0ms
  eslint:config-file Loading plugin:@typescript-eslint/recommended +567ms
  eslint:config-file Attempting to resolve @typescript-eslint/eslint-plugin +1ms
  eslint:config-file Loading JS config file: C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\@typescript-eslint\eslint-plugin\dist\index.js +2ms
  eslint:config Using C:\Users\G-Rath\workspace\projects-personal\js-bugs\.eslintrc +627ms
  eslint:config-ops Using config from partial cache +0ms
  eslint:config-ops Apply environment settings to config +4ms
  eslint:linter Linting code for C:\Users\G-Rath\workspace\projects-personal\js-bugs\index.ts (pass 1) +0ms
  eslint:traverser Unknown node type "ClassProperty": Estimated visitor keys ["type","key","value","computed","static","readonly","range","loc","decorators","accessibility"] +0ms
  eslint:traverser Unknown node type "Decorator": Estimated visitor keys ["type","expression","range","loc"] +5ms
  eslint:traverser Unknown node type "TSNonNullExpression": Estimated visitor keys ["type","expression","range","loc"] +2ms
  eslint:linter An error occurred while traversing +868ms
  eslint:linter Filename: C:\Users\G-Rath\workspace\projects-personal\js-bugs\index.ts +1ms
  eslint:linter Line: 2 +1ms
  eslint:linter Parser Options: { sourceType: 'module',
  project: 'tsconfig.json',
  ecmaVersion: 6,
  ecmaFeatures: { globalReturn: false } } +2ms
  eslint:linter Parser Path: C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\@typescript-eslint\parser\dist\parser.js +2ms
  eslint:linter Settings: {} +2ms
TypeError: Cannot read property 'declarations' of undefined
Occurred while linting C:\Users\G-Rath\workspace\projects-personal\js-bugs\index.ts:2
    at Object.getDeclaration (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\@typescript-eslint\eslint-plugin\dist\util\types.js:104:45)
    at isPossiblyUsedBeforeAssigned (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\@typescript-eslint\eslint-plugin\dist\rules\no-unnecessary-type-assertion.js:112:38)
    at TSNonNullExpression (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\@typescript-eslint\eslint-plugin\dist\rules\no-unnecessary-type-assertion.js:142:25)
    at listeners.(anonymous function).forEach.listener (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\eslint\lib\util\safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\eslint\lib\util\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\eslint\lib\util\node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\eslint\lib\util\node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\eslint\lib\util\node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (C:\Users\G-Rath\workspace\projects-personal\js-bugs\node_modules\eslint\lib\code-path-analysis\code-path-analyzer.js:632:23)

Versions

package version
@typescript-eslint/eslint-plugin 1.9.0
@typescript-eslint/parser 1.9.0
TypeScript 3.4.5
ESLint 5.16.0
node 10.15.3
npm 6.9.0
@G-Rath G-Rath added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 15, 2019
@bradzacher bradzacher added bug Something isn't working and removed triage Waiting for team members to take a look labels May 15, 2019
@bradzacher bradzacher added the has pr there is a PR raised to close this label May 16, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants