Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: [no-misused-promises] Specific function declaration syntax circumvents the rule with TypeScript strict enabled #11699

@theneva

Description

@theneva

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

https://typescript-eslint.io/play/#ts=5.9.3&fileType=.tsx&code=GYVwdgxgLglg9mABAWxFAhlApgCjgB1gQGcB%2BALkQG9EEBlECCLY4nASkoDc4YATRAF921AFCJEAekmIAUiGJREfOInRgAnlAAWMMAHNEAdxg7aheGGKIoq5OgDWWRABUN%2BLHQgAnGIUTa6Pj4GgB04ogQJHAANlihMXD6eBYk7ADcooKiotKuutb6WFDW3lj4cN7YfOGoGNg4NPSMzKyU6MQakIgciAC8AHzUQkLsOXkuBcpwLIhgcFC1aJi4NB1dELRgDEwsbCI0gqOiQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oFtLlZkiACa1i0Dr0GoMkRNHHRI4MAF8QKoA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eFYDAruuGAL4g9A&tokens=false

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

{
  "compilerOptions": {
    "strict": true
  }
}

(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.

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