{"record":{"id":"29e5337f0aa10db4","repo":"microsoft/TypeScript","slug":"symbol-asyncdispose-is-not-defined","errorCode":null,"errorMessage":"Symbol.asyncDispose is not defined.","messagePattern":"Symbol\\.asyncDispose is not defined\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/compiler/factory/emitHelpers.ts","lineNumber":1390,"sourceCode":"    scoped: false,\r\n    text: `\r\n            var __classPrivateFieldIn = (this && this.__classPrivateFieldIn) || function(state, receiver) {\r\n                if (receiver === null || (typeof receiver !== \"object\" && typeof receiver !== \"function\")) throw new TypeError(\"Cannot use 'in' operator on non-object\");\r\n                return typeof state === \"function\" ? receiver === state : state.has(receiver);\r\n            };`,\r\n};\r\n\r\nconst addDisposableResourceHelper: UnscopedEmitHelper = {\r\n    name: \"typescript:addDisposableResource\",\r\n    importName: \"__addDisposableResource\",\r\n    scoped: false,\r\n    text: `\r\n        var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {\r\n            if (value !== null && value !== void 0) {\r\n                if (typeof value !== \"object\" && typeof value !== \"function\") throw new TypeError(\"Object expected.\");\r\n                var dispose, inner;\r\n                if (async) {\r\n                    if (!Symbol.asyncDispose) throw new TypeError(\"Symbol.asyncDispose is not defined.\");\r\n                    dispose = value[Symbol.asyncDispose];\r\n                }\r\n                if (dispose === void 0) {\r\n                    if (!Symbol.dispose) throw new TypeError(\"Symbol.dispose is not defined.\");\r\n                    dispose = value[Symbol.dispose];\r\n                    if (async) inner = dispose;\r\n                }\r\n                if (typeof dispose !== \"function\") throw new TypeError(\"Object not disposable.\");\r\n                if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };\r\n                env.stack.push({ value: value, dispose: dispose, async: async });\r\n            }\r\n            else if (async) {\r\n                env.stack.push({ async: true });\r\n            }\r\n            return value;\r\n        };`,\r\n};\r\n\r","sourceCodeStart":1372,"sourceCodeEnd":1408,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/compiler/factory/emitHelpers.ts#L1372-L1408","documentation":"Runtime TypeError from `__addDisposableResource` in async mode (`await using`). When the value is an object/function and `async` is true, the helper requires `Symbol.asyncDispose` to exist on the runtime; if it is missing, it throws before even reading the value's disposer. The symbol is part of the Explicit Resource Management proposal and may be absent on older runtimes.","triggerScenarios":"`await using x = obj` compiled with the downlevel helper, run on a runtime that lacks `Symbol.asyncDispose` (older Node.js, older browsers, some bundler targets). Not thrown when `async` is false (plain `using`) or when native `await using` is used.","commonSituations":"Shipping transpiled `await using` code to a Node version below the supported floor; bundling with a low `target` for browser compatibility without polyfilling the symbol; mixing polyfill state across packages.","solutions":["Polyfill `Symbol.asyncDispose` before any `await using` runs (`(Symbol as any).asyncDispose ??= Symbol(\"Symbol.asyncDispose\")`).","Raise the runtime / Node version to one that ships `Symbol.asyncDispose`.","Switch the binding to plain `using` (with `Symbol.dispose`) if async disposal is not required.","Set `target` high enough that `await using` is emitted natively on a runtime that supports it."],"exampleFix":"// before: await using transpiled on an old runtime -> TypeError\n// after: polyfill before use\n(Symbol as any).asyncDispose ??= Symbol(\"Symbol.asyncDispose\");\nawait using r = openAsyncResource();","handlingStrategy":"validation","validationCode":"// Feature-detect and polyfill before binding with `await using`:\nif ((Symbol as any).asyncDispose === undefined) {\n  (Symbol as any).asyncDispose = Symbol(\"Symbol.asyncDispose\");\n}","typeGuard":"function hasAsyncDispose(): boolean { return (Symbol as any).asyncDispose !== undefined; }","tryCatchPattern":null,"preventionTips":["Polyfill `Symbol.asyncDispose`/`Symbol.dispose` at application entry when targeting mixed runtimes.","Set a runtime-engines floor that matches your `target`/`lib` disposable support.","Prefer plain `using` when async cleanup is not actually needed."],"tags":["disposable","async-disposable","using","runtime","polyfill","emit-helpers"],"backgroundTag":null,"analyzedSha":"b465fdbfe175304d9b977da137b2c178ae1091d3","analyzedAt":"2026-08-12T05:38:42.698Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}