'await using' statements are only allowed at the top level of a file when tha...
Production Risk
Build will fail; resolve before shipping.
A type-checking error (TS2853): 'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.. This diagnostic is emitted by the TypeScript compiler when 'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module..
- 1await used outside an async function, or async/await return type mismatch
TypeScript compiler reports TS2853 during type checking.
// Triggers TS2853
// 'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.expected output
error TS2853: 'await using' statements are only allowed at the top level of a file when that file is a module, but this file has no imports or exports. Consider adding an empty 'export {}' to make this file a module.Fix
Add 'async' to the containing function
WHEN Using await outside an async function
// Mark the function as async
async function fetchData() {
const result = await fetch('/api/data');
return result.json();
}Why this works
await can only be used inside async functions; the 'async' keyword makes the function return a Promise.
TypeScript Compiler Diagnostics
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev