Skip to main content

js/noAsyncPromiseExecutor

disallow using an async function as a Promise executor

ESLint Equivalent: no-async-promise-executor

Examples

Invalid

new Promise(async function foo() {})

 file.ts:1:12 lint/js/noAsyncPromiseExecutor ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Promise executor functions should not be async.

    new Promise(async function foo() {})
                ^^^^^^^^^^^^^^^^^^^^^^^

  This can lead to lost errors and unnecessary indirection.


new Promise(async () => {})

 file.ts:1:12 lint/js/noAsyncPromiseExecutor ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Promise executor functions should not be async.

    new Promise(async () => {})
                ^^^^^^^^^^^^^^

  This can lead to lost errors and unnecessary indirection.


new Promise(((((async () => {})))))

 file.ts:1:16 lint/js/noAsyncPromiseExecutor ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

  Promise executor functions should not be async.

    new Promise(((((async () => {})))))
                    ^^^^^^^^^^^^^^

  This can lead to lost errors and unnecessary indirection.

Valid

new Promise(() => {})
new Promise(() => {}, async function unrelated() {})
class Foo {} new Foo(async () => {})