TypeScript Syntax
await using — asynchronous resource disposal
Registers a resource whose asynchronous cleanup is awaited on scope exit, with synchronous disposal as a fallback when applicable. Use it in an async context or supported top-level module context. A disposable initializer is not automatically awaited simply because the declaration says await using. Observed output: 'body\ndisposed\ndone'. Local verification: TypeScript 5.8.3, strict mode, ES2022, CommonJS, Node.js 22.16.0. Disposable library declarations are enabled for the fixture suite.
Formal Syntax & Structure
typescript syntaxtypescript
await using resource = disposableExpression;Working Example
Example Snippettypescript
async function run() { await using resource = { async [Symbol.asyncDispose]() { await Promise.resolve(); console.log("disposed"); } }; console.log("body");}run().then(() => console.log("done"));