-
Notifications
You must be signed in to change notification settings - Fork 178
Open
Labels
bugSomething isn't workingSomething isn't working
Description
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
phaux
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working