Skip to content

[no-misused-promises] checksVoidReturn=true doesn't catch the error when variadic arguments are used (like ...handlers: Array<() => void>) #4015

Closed
@dko-slapdash

Description

@dko-slapdash

This issue affects e.g. express used with new route handlers which are required to be non-async in their TS typings. I think in case of variadic arguments, the plugin verifies just the 1st argument and, if it's okay, doesn't even check the rest of the arguments.

  • 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

{
  "rules": {
     "@typescript-eslint/no-misused-promises": "error",
  }
}
function get2(_h1: () => void, _h2: () => void) {}

function get(..._handlers: Array<() => void>) {}

get2(
  () => {},
  async () => {} // <-- fails, which is what we want
);

get(
  () => {},
  async () => {}  // <-- this must fail too, but it does not
);

Expected Result

Both get() and get2() calls must raise an eslint error.

Actual Result

Only get2() is treated as incorrect, and get() is fine - although it should fail too:

image

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 5.0.0
@typescript-eslint/parser 5.0.0
TypeScript 4.4.4
ESLint 8.0.1
node 16.11.1

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