Skip to content

Bug: [@typescript-eslint/require-await] False positive when implementing async interface with sync function #7450

Closed as not planned
@panstromek

Description

@panstromek

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.1.6&fileType=.ts&code=LAKAlgdgLgpgTgMwIYGMYAICCBnAnhFAZQAsB7Ad3QG9R071szyAudACgEp0BeAPnQAKcUgFsw2GAB4AbqTAATXqAC%2BoUAgCuBKGFIR0I0igDWOfCgBiETqzMESFarXpwYUDXH00Q9X%2BiR4BAxMnE4%2BfhEoetikADYwAHSxpADmbADkEKQADukczhG%2Bru6eBX6q4XQVFUA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6aRAR1ko9oEMA7v0r50URNGgB7aJHBgAviEVA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

interface AsyncShow {
    show: () => Promise<void>
}

function mockAsyncFn(): AsyncShow {
    return {
        async show() {
            console.log('nop')
            return
        }
    }
}

ESLint Config

module.exports = {
  parser: "@typescript-eslint/parser",
  rules: {
    "@typescript-eslint/require-await": "error"
  },
};

tsconfig

{
  "compilerOptions": {
    // ...
  }
}

Expected Result

No error.

Actual Result

Error on show implementation: Async method 'show' has no 'await' expression.

Additional Info

Since the method just implement an interface (which might be out of scope), it shouldn't require await keyword if it is not necessary for this specific implementation.

The way to fix this is to use Promise.resolve() inside non-async function, but that's unnecessarily verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginworking as intendedIssues that are closed as they are working as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions