Skip to content

require-await rule should be irrelevant for strong-typed callbacksΒ #1428

@dimikot

Description

@dimikot

Inability to use calbacks like async () => 42 doesn't allow to use some external libraries where we have no control over the typing of the callbacks.

Lint Name

require-await

Code Snippet

// Imagine we have an external library that requires an async callback to be passed...
interface OptionsWithCallback {
  cb: () => Promise<number>;
}

// We have some function from that library.
function some(options: OptionsWithCallback) {
  return console.log(options.cb());
}

// Lint rule doesn't allow to do this:
// Async arrow function has no 'await' expression or 'await using' declaration.
// Remove 'async' keyword from the function or use 'await' expression or 'await using'
// declaration inside.deno-lint(require-await)
some({ cb: async () => 42 });

// And we obviously can't do this as well (not a lint issue, it's just TS typing):
// Type 'number' is not assignable to type 'Promise<number>'.
some({ cb: () => 42 });

// So, the only work-around require-await forces us to do is this ugliness.
some({ cb: async () => await Promise.resolve(42) });

Version

deno 2.2.3 (stable, release, aarch64-apple-darwin)
v8 13.4.114.11-rusty
typescript 5.7.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions