Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 556 Bytes

no-top-level-await.md

File metadata and controls

31 lines (21 loc) · 556 Bytes

no-top-level-await

This prevents the use of await at the top-level of documents (outside of an async function context)

await asyncMethod();

const results = await getAsyncResults();

These will not be allowed because they are not supported in the following browsers:

  • Edge < 89
  • Safari < 15
  • Firefox < 89
  • Chrome < 89

What is the Fix?

You can wrap your await in an async Immediately Invoking Function Expression (IIFE).

(async () => {
    await asyncMethod();

    const results = await getAsyncResults();
})();