Skip to content

Bug: [require-await] fails to infer types for function declarations implementing interfaces #11085

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 tasks done
FauxFaux opened this issue Apr 17, 2025 · 2 comments
Closed
4 tasks done
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended

Comments

@FauxFaux
Copy link

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.8.2&fileType=.tsx&code=PQKgBApgzgNglgOwC5gAJIJ4AdoGMBOcWSAtNPMsPhAI4Cuc1JAhgO7NxIBcYARBPnwB7fLzAhgAKEmIkAgGbNcEMADEhQsAG9JYMPIQ8AFAEowAXgB8YAArCAtnCgQAPADchcACaWA3JIBfaXk6BFwkOCEEMHtmAGsIUx51TR09XCioFHkNZI0LbV09fUMwZigMMLBTC2s04vTMoRgIADoYIQBzIwByAAsIGA6wVhEYLx6TfwaAgBoigOmwaiQ6fGicoX8goA&eslintrc=N4KABGBEBOCuA2BTAzpAXGYBfEWg&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Repro Code

/* eslint @typescript-eslint/require-await: "error" */

interface Foo {
  fn: () => Promise<void>;
}

function make(): Foo {
  const foo: Foo = {
    fn: async () => {
      console.log('hello world');
    },
  };
  return foo;
}

ESLint Config

module.exports = {
  "rules": {}
}

tsconfig

{
  "compilerOptions": {
    "strictNullChecks": true
  }
}

Expected Result

The rule believes that the fn implementation inside the interface must not be async, as it lacks an await expression or a return Promise... However, making it not async causes the code to fail to compile: it must be async according to the types. I believe the purpose of this rule (over the eslint one) is to use this type information to not flag this code as incorrect.

Actual Result

Async method 'fn' has no 'await' expression. 9:5 - 9:15
> Remove 'async'.

Additional Info

No response

@FauxFaux FauxFaux added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels Apr 17, 2025
@FauxFaux
Copy link
Author

Okay and now I find this much older discussion. I strongly disagree, but if that is still the decision then I understand.

#7450 (comment)

@bradzacher
Copy link
Member

This is working as expected -- if you're using async as a side-effect to make a sync function return a promise then you should use a disable comment.

@bradzacher bradzacher added duplicate This issue or pull request already exists working as intended Issues that are closed as they are working as intended and removed triage Waiting for team members to take a look labels Apr 17, 2025
@github-actions github-actions bot added the locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. label Apr 25, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working duplicate This issue or pull request already exists locked due to age Please open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing. package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin working as intended Issues that are closed as they are working as intended
Projects
None yet
Development

No branches or pull requests

2 participants