How to avoid "no-promise-executor-return" in this situation?

Advertisements

code:

export function sleep(ms: number): Promise<void> {
    return new Promise<void>((resolve) => setTimeout(resolve, ms));
}

Docs link:
no-promise-executor-return

I have tried in many ways to avoid this error.
Unfortunately, to no avail.

>Solution :

This is an arrow function thing. () => 0 is the same as function() { return 0 }. So your promise executor does return the response of setTimeout. In order to avoid this wrap the setTimeout call in a function body. (() => { setTimeout(...) }).

Leave a ReplyCancel reply