Skip to content

[no-misused-promises] Suggestion: check more AST positions #4523

Closed
@uhyo

Description

@uhyo

Hello, I think the no-misused-promises rule could be improved to perform the checks in a few more positions, so here is proposal:

  • 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"
  }
}
declare function doSomething(value: unknown): Promise<void>;

// Function argument: current version of the rule emits error
[1, 2, 3].forEach(async value => {
  await doSomething(value);
});

// variable: current version of the rule does NOT emit error
const func: () => void = async () => {
  await doSomething(123);
};

type Obj = {
  func: () => void
};

// Contextually typed property: current version of the rule does NOT emit error
const obj: Obj = {
  func: async () => {
    await doSomething(123);
  }
};

const Component = (obj: Obj) => null;

// JSX prop: current version of the rule does NOT emit error
<Component func={async () => {
  await doSomething(123);
}} />;

Expected Result

The rule reports error for all cases above.

Actual Result

Error is reported only for the first case.

Additional Info

Versions

package version
@typescript-eslint/eslint-plugin 5.10.2
@typescript-eslint/parser 5.10.2
TypeScript 4.5.5
ESLint 8.8.0
node 16.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions