Skip to content

Bug: [strict-void-return] false positive when function has overload with void-returning function and Promise-returning function #11960

@reduckted

Description

@reduckted

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.5.2&fileType=.tsx&code=JYOwLgpgTgZghgYwgAgBIHt0GsBiBXEBMYdEAHgBVkIAPSEAEwGdkA3dYB5AHzUy2QBeNhwYA%2BZAG8AsAChkyABQwQALiUBKIRPacN6igG45C5Ws3bkABSjoAtsCYQyu8fuRG5AXzlyEAGzgmFgxsKR9ZOQYIALgoFFY45AAjCBh0eIBRRAALdVDcAiIScgKxY0jZVPSs3MVFLUEJSWQvDQq5aoyIbIQcxSCAT0ILJqlW9rkgA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6ZfKsugNwHtKAE1rRE%2BWNCbooAdwCGkyODABfECqA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

interface HookFunction<T extends void | Hook = void> {
  (fn: () => void): T;
  (fn: () => Promise<void>): T;
}

class Hook {}

declare var beforeEach: HookFunction<Hook>;

beforeEach(() => {});

beforeEach(async () => { });

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/strict-void-return": "warn"
};

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

beforeEach(async () => { }); should be valid because the parameter type is a function that returns a Promise.

Actual Result

beforeEach(async () => { }); produces a warning because the parameter is considered to be a function that returns void.

Additional Info

The specific case where I encountered this problem is with Mocha's beforeEach method.

https://github.com/DefinitelyTyped/DefinitelyTyped/blob/49a2604fdf497676f6bc005b4869729d5b0d05bd/types/mocha/index.d.ts#L392

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issuebugSomething isn't workingpackage: 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