Promise executor cannot be an async function

이 페이지는 아직 한국어로 제공되지 않으며 번역 작업 중입니다. 번역에 관한 질문이나 의견이 있으시면 언제든지 저희에게 연락해 주십시오.

Metadata

ID: typescript-best-practices/no-async-promise-executor

Language: TypeScript

Severity: Error

Category: Best Practices

Description

An async Promise executor won’t surface exceptions if it fails. If you are already awaiting results in the executor, the Promise itself might not be required; please review your implementation.

Non-Compliant Code Examples

new Promise(async function foo(resolve, reject) {})
new Promise(async (resolve, reject) => {})

Compliant Code Examples

new Promise((resolve, reject) => {})
new Promise((resolve, reject) => {}, async function unrelated() {})
new Foo(async (resolve, reject) => {})
https://static.datadoghq.com/static/images/logos/github_avatar.svg https://static.datadoghq.com/static/images/logos/vscode_avatar.svg jetbrains

Seamless integrations. Try Datadog Code Analysis