8000 [promise-function-async] problem with exported functions · Issue #227 · typescript-eslint/typescript-eslint · GitHub
[go: up one dir, main page]

Skip to content

[promise-function-async] problem with exported functions #227

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
berlysia opened this issue Feb 7, 2019 · 3 comments · Fixed by #287
Closed

[promise-function-async] problem with exported functions #227

berlysia opened this issue Feb 7, 2019 · 3 comments · Fixed by #287
Assignees
Labels
bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@berlysia
Copy link
berlysia commented Feb 7, 2019

Repro

{
  "rules": {
    "@typescript-eslint/promise-function-async": [
      "error",
      {
        "allowedPromiseNames": [],
        "checkArrowFunctions": false,
        "checkFunctionDeclarations": true,
        "checkFunctionExpressions": false,
        "checkMethodDeclarations": false
      }
    ]
  }
}

code 1:

export function valid(n: number) { return n; }

code 2

export default function invalid(n: number) { return n; }

Expected Result
code 1 - no error
code 2 - lint error

Actual Result

TypeError: Cannot read property 'resolvedReturnType' of undefined
    at Object.getReturnTypeOfSignature (/path/to/repo/node_modules/typescript/lib/typescript.js:38106:28)
    at validateNode (/path/to/repo/node_modules/@typescript-eslint/eslint-plugin/lib/rules/promise-function-async.js:91:34)
    at FunctionDeclaration (/path/to/repo/node_modules/@typescript-eslint/eslint-plugin/lib/rules/promise-function-async.js:111:11)
    at listeners.(anonymous function).forEach.listener (/path/to/repo/node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)
    at Object.emit (/path/to/repo/node_modules/eslint/lib/util/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/path/to/repo/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (/path/to/repo/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (/path/to/repo/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (/path/to/repo/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:632:23)

Additional Info

No problem with non-exported function declarations:

function valid(n: number) { return n; }
function invalid(p: Promise<void>) { return p; } // lint error

and also with arrow functions ( checkArrowFunctions: true ):

export const valid = (n: number) => n;
export const invalid = (p: Promise<void>) => p; // lint error

Versions

package version
@typescript-eslint/eslint-plugin 1.2.0
@typescript-eslint/parser 1.2.0
TypeScript 3.2.4, 3.3.0
ESLint 5.13.0
node 11.8.0
npm 6.7.0
@berlysia berlysia added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Feb 7, 2019
@armano2 armano2 added bug Something isn't working and removed triage Waiting for team members to take a look labels Feb 7, 2019
@bradzacher
Copy link
Member

Bug is specifically with the line

https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/lib/rules/promise-function-async.js#L87

const originalNode = parserServices.esTreeNodeToTSNodeMap.get(node);

This is returning undefined.

It happens because of how we create the ExportDefaultDeclaration (https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/typescript-estree/src/node-utils.ts#L458-L497).

Because the FunctionDeclaration node is not created as a standalone node, it never gets added to the ts -> es node map (https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/typescript-estree/src/convert.ts#L120-L123).

@doberkofler
Copy link
Contributor

Hitting the same problem in my code base

@WolfieZero
Copy link

I'm the TypeError: Cannot read property 'resolvedReturnType' of undefined with the following code:

class Foo {
    constructor() {
        // ...
    }

    bar(): string {
        return 'baz';
    }
}

I believe the issue with me is coming from the constructor()

Versions

Package Version
@typescript-eslint/eslint-plugin ^1.3.0
eslint-config-xo-typescript ^0.8.0
typescript ^3.3.3
xo 0.24.0

@armano2 armano2 self-assigned this Feb 14, 2019
sindresorhus referenced this issue in refined-github/refined-github Feb 18, 2019
kaicataldo pushed a commit to kaicataldo/typescript-eslint that referenced this issue Aug 27, 2019
…pescript-eslint#227)

- correct url in no-misused-new
- add tslint addontation to no-namespace
- enable rules: eslint-plugin/no-deprecated-context-methods, eslint-plugin/prefer-output-null

fixes: typescript-eslint#213
fixes: typescript-eslint#212
@typescript-eslint typescript-eslint locked as resolved and limited conversation to collaborators Feb 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 package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
0