Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[no-misused-promises] async react callback properties when void expected #4619

Closed
Assignees
JoshuaKGoldberg
Labels
accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin
@jlowcs

Description

@jlowcs
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I haveread the FAQ and my problem is not listed.

Repro

{"rules": {"no-misused-promises": ["error"]  }}
<buttontype="button"onClick={async()=>{awaitdoSomethingAsync();}}>action</button>

or

<buttontype="button"onClick={doSomethingAsync}>action</button>

Expected Result

No linting error.

Actual Result

A linting error is being reported:

src/app/App.tsx  129:13  error  Promise-returning function provided to attribute where a void return was expected  @typescript-eslint/no-misused-promises

One way to avoid this error would be to wrap the callback's content in an async IIFE:

<buttontype="button"onClick={()=>{(async()=>{awaitdoSomethingAsync();})();}}>action</button>

But that's not really practical when the callback is an existing function (like the 2nd example above).

Additional Info

I guess this new behavior is kind of expected, but it's probably gonna breaks linting on a lot of React projects (including ours, which has now over 100 erros following this update). I'll welcome any suggestion as to how to address it without simply disabling the rule (and risk missing some potential bugs that were detected before).

Versions

packageversion
@typescript-eslint/eslint-plugin5.13.0
@typescript-eslint/parser5.13.0
TypeScript4.5.5
ESLint8.10.0
node16.13.2

Metadata

Metadata

Labels

accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: 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


    [8]ページ先頭

    ©2009-2025 Movatter.jp