Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed
Description
- 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
package | version |
---|---|
@typescript-eslint/eslint-plugin | 5.13.0 |
@typescript-eslint/parser | 5.13.0 |
TypeScript | 4.5.5 |
ESLint | 8.10.0 |
node | 16.13.2 |