我的小项目中有这段代码:
close(flush = false): void {
if (this.ws?.CLOSING || this.ws?.CLOSED) {
return;
}
if (flush) {
// I really don't know how to fix that
// eslint-disable-next-line @typescript-eslint/promise-function-async
const sendPromises = this.state.queue.map((message) =>
this.sendAsync(message)
);
void Promise.all(sendPromises).then(() => this.ws?.close());
} else {
this.ws?.close();
}
}
当我在上面运行xo
(使用 typescript-eslint)时,@typescript-eslint/promise-function-async
失败了。我做了一些更改,但仍然失败。谁能给我解释为什么这不起作用?
我尝试了什么:
// first
const sendPromises: Promise<void> = this.state.queue.map((message) => this.sendAsync(message));
// second
const sendPromises = this.state.queue.map((message): Promise<void> => this.sendAsync(message));