Skip to content
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

Disable require-await by default #1170

Open
not-my-profile opened this issue Jun 19, 2023 · 3 comments
Open

Disable require-await by default #1170

not-my-profile opened this issue Jun 19, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@not-my-profile
Copy link
Contributor

Consider the following code:

interface Foo {
  bar(): Promise<number>;
}

class Bar implements Foo {
  async bar() {
    return 1;
  }
}

deno lint currently by default complains:

(require-await) Async method 'bar' has no 'await' expression.
  async bar() {
        ^^^
    at /tmp/foo.ts:6:9

    hint: Remove 'async' keyword from the function or use 'await' expression inside.
    help: for further information visit https://lint.deno.land/#require-await

However if you follow that hint and remove the async keyword you actually introduce the following TypeScript error (as reported by deno check):

error: TS2416 [ERROR]: Property 'bar' in type 'Bar' is not assignable to the same property in base type 'Foo'.
  Type '() => number' is not assignable to type '() => Promise<number>'.
    Type 'number' is not assignable to type 'Promise<number>'.
  bar() {
  ~~~

Since implementing some interface that requires an async function is incredibly common in TypeScript and deno lint currently has absolutely no clue about types (see #1138) and therefore currently cannot detect that the async keyword is actually needed, I think it would be best to disable the require-await rule by default (i.e. removing it from the recommended rules set).

(sidenote: ESLint also doesn't recommend require-await)

@yacinehmito
Copy link

I support this suggestion. Disabling this rule is the first thing I do when I setup a project with Deno. It's super annoying.

@jordanbtucker
Copy link

jordanbtucker commented Aug 28, 2023

Alternatively, the rule could catch situations like these and not report them as errors. Although, that might require type checking.

@karfau
Copy link

karfau commented May 6, 2024

There is also https://typescript-eslint.io/rules/promise-function-async/ which makes so much sense to me.
What is it about type checking, is it not possible for deno to do that?
Or asked differently, is there any chance that deno will ever have a rule like promise-function-async?

(And with the background of JSR "performant types" in which, if I understood it correctly, all exported functions have to declare their return type, maybe it would even be possible to that without type checks, by enforcing declaring the return type on all functions?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants