Skip to content

[@typescript-eslint/explicit-function-return-type] Inconsistent on arrow functions #1009

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
ghost opened this issue Sep 25, 2019 · 1 comment · Fixed by #1021
Closed

[@typescript-eslint/explicit-function-return-type] Inconsistent on arrow functions #1009

ghost opened this issue Sep 25, 2019 · 1 comment · Fixed by #1021
Labels
bug Something isn't working good first issue Good for newcomers has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@ghost
Copy link

ghost commented Sep 25, 2019

Repro

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "tsconfigRootDir": ".",
    "project": "tsconfig.json"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking",
    "prettier/@typescript-eslint",
    "plugin:prettier/recommended"
  ],
  "env": {
    "node": true
  },
  "rules": {
    "@typescript-eslint/promise-function-async": "error"
  }
}
public async listen(): Promise<Server> {
    if (this.server.listening) {
        return this.server;
    }

    return new Promise(resolve => { // 1) ERROR
        this.server.once("listening", () => resolve(this.server)); // 2) WORK AS EXPECTED
        this.server.listen(Number(process.env.SERVER_PORT), process.env.SERVER_HOST);
    });
}

Expected Result

No errors.

Actual Result

Error:

20:28 warning Missing return type on function @typescript-eslint/explicit-function-return-type

Additional Info

The line commented with // 1) ERROR cause the error, while the line commented with // 2) WORK AS EXPECTED work as expected. It don't seems consistent.

Versions

package version
@typescript-eslint/eslint-plugin 2.3.1
@typescript-eslint/parser 2.3.1
TypeScript 3.6.2
ESLint 6.4.0
node 10.16.3
npm 6.11.3
@ghost ghost added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Sep 25, 2019
@bradzacher
Copy link
Member

This is a bug because new Promise() is a NewExpression, not a CallExpression.
The rule is only coded to include CallExpressions as valid for allowTypedFunctionExpressions.

@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 Sep 25, 2019
@bradzacher bradzacher added the has pr there is a PR raised to close this label Sep 30, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 2, 2021
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 has pr there is a PR raised to close this package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant