-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
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
Repro Code
function mutate(options?: { onSuccess(): void }) {
// Just do anything with options to make TypeScript happy.
console.log(options);
}
// This gets reported:
mutate({ onSuccess: async () => { } })
// This does not:
mutate({ async onSuccess() { } })ESLint Config
{
"rules": {
"@typescript-eslint/no-misused-promises": "error"
}
}tsconfig
(strict is turned on by default, so you don't actually need to set it to reproduce the behaviour. I just added it so it's easier to test the repro by setting it to false.)
Expected Result
I expected the rule to report a misused promise for both declaration styles.
I did not expect TypeScript's strict compiler option to change the rule's behaviour.
Actual Result
The rule only reports the onSuccess: async () => { … } case.
Additional Info
I understand that the two styles of declaring the options object are not completely interchangeable, but I still think it's weird enough to deserve a bug report 😄
Note that this behaviour only triggers when the options argument is marked optional. Declaring the function as function mutate(options: { … }) { … } (i.e., not options?: { …}) causes the rule to report the misused promise.
{ "compilerOptions": { "strict": true } }