Skip to content

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

Closed
@G-Rath

Description

@G-Rath

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghas prthere is a PR raised to close thispackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions