Skip to content

[no-unsafe-return] TypeError: checker.getTypeArguments is not a function #1807

@tao-cumplido

Description

@tao-cumplido

The rule no-unsafe-return exits with an error on array types with TS versions < 3.7
Apparently the rule uses the method getTypeArguments which was only added to the TS api in version 3.7: https://github.com/microsoft/TypeScript-wiki/blob/master/API-Breaking-Changes.md

Repro

module.exports = {
   parser: '@typescript-eslint/parser',
   plugins: ['@typescript-eslint'],
   parserOptions: {
      project: './tsconfig.json',
   },
   rules: {
      '@typescript-eslint/no-unsafe-return': 'error',
   },
};
function foo() {
   return [];
}

I created a minimal repo here: https://github.com/tao-cumplido/ts-eslint-error
If you bump the TS version to 3.7 it works as expected.

Expected Result
no error

Actual Result

TypeError: checker.getTypeArguments is not a function
Occurred while linting C:\Users\taocu\Desktop\Projekte\ts-eslint-error\test.ts:2
    at Object.isAnyOrAnyArrayTypeDiscriminated (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\@typescript-eslint\eslint-plugin\dist\util\types.js:242:31)
    at checkReturn (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\@typescript-eslint\eslint-plugin\dist\rules\no-unsafe-return.js:49:34)
    at ReturnStatement (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\@typescript-eslint\eslint-plugin\dist\rules\no-unsafe-return.js:105:17)
    at C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\eslint\lib\linter\safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\eslint\lib\linter\safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\eslint\lib\linter\node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\eslint\lib\linter\node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\eslint\lib\linter\node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (C:\Users\taocu\Desktop\Projekte\ts-eslint-error\node_modules\eslint\lib\linter\code-path-analysis\code-path-analyzer.js:634:23)
error Command failed with exit code 2.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 2.25.0
@typescript-eslint/parser 2.25.0
TypeScript 3.6.x
ESLint 6.8.0
node 13.10.1
npm 6.13.7

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy