Skip to content

[triple-slash-reference] TypeError: Cannot read property 'value' of undefined #2762

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
3 tasks done
timplateus opened this issue Nov 13, 2020 · 5 comments · Fixed by #2788
Closed
3 tasks done

[triple-slash-reference] TypeError: Cannot read property 'value' of undefined #2762

timplateus opened this issue Nov 13, 2020 · 5 comments · Fixed by #2788
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@timplateus
Copy link

timplateus commented Nov 13, 2020

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

.eslintrc.json

{
  "root": true,
  "overrides": [
    {
      "files": ["*.ts"],
      "parserOptions": {
        "project": [
          "tsconfig.json"
        ],
        "createDefaultProgram": true
      },
      "extends": ["plugin:@typescript-eslint/recommended"]
    }
  ]
}

.ts

/// <reference types="@types/googlemaps" />
import DistanceMatrixResponse = google.maps.DistanceMatrixResponse;

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "src",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "downlevelIteration": true,
    "experimentalDecorators": true,
    "module": "es2020",
    "moduleResolution": "node",
    "importHelpers": true,
    "resolveJsonModule": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": false,
    "strictInjectionParameters": true,
    "preserveWhitespaces": true
  }
}

Expected Result

Evaluate the file, and pass/reject the rule

Actual Result

Unhandled Exception (see below). Note that disabling all rules (//eslint-disable-next-line) for the problematic line did not stop the exception from occurring.

TypeError: Cannot read property 'value' of undefined
Occurred while linting corrupted-file.ts:2
    at ...\node_modules\@typescript-eslint\eslint-plugin\dist\rules\triple-slash-reference.js:67:53
    at Array.forEach (<anonymous>)
    at hasMatchingReference (...\node_modules\@typescript-eslint\eslint-plugin\dist\rules\triple-slash-reference.js:66:24)
    at TSImportEqualsDeclaration (...\node_modules\@typescript-eslint\eslint-plugin\dist\rules\triple-slash-reference.js:88:21)
    at ...\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (...\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (...\node_modules\eslint\lib\linter\node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (...\node_modules\eslint\lib\linter\node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (...\node_modules\eslint\lib\linter\node-event-generator.js:297:14)
Process finished with exit code -1

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 4.7.0
@typescript-eslint/parser 4.7.0
TypeScript 4.0.5
ESLint 7.13.0
node 14.15.0
@timplateus timplateus added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Nov 13, 2020
@timplateus
Copy link
Author

To resolve this issue, I disabled this rule in .eslintrc.json:

{
...
"extends": ["plugin:@typescript-eslint/recommended"],
"rules": {
  "@typescript-eslint/triple-slash-reference": "off"
}
...
}

@bradzacher
Copy link
Member

Easy bug to fix

const source = (node.moduleReference as TSESTree.TSExternalModuleReference)

This line makes the assumption that .moduleReference is always a TSExternalModuleReference.
In this instance it's not as it's a TSQualifiedName.

Happy to accept a PR

@bradzacher bradzacher added bug Something isn't working good first issue Good for newcomers and removed triage Waiting for team members to take a look labels Nov 13, 2020
@deepenpatel3
Copy link

I would like to take it, I have never contributed to open source projects. Can you please share some insights on how to solve it?

@ddubrava
Copy link
Contributor

ddubrava commented Nov 14, 2020

I would like to take it, I have never contributed to open source projects. Can you please share some insights on how to solve it?

@ddubrava
Copy link
Contributor

@deepenpatel3 👋 are you working on the issue?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants