{"record":{"id":"02b87beb37521486","repo":"microsoft/TypeScript","slug":"symbol-dispose-is-not-defined","errorCode":null,"errorMessage":"Symbol.dispose is not defined.","messagePattern":"Symbol\\.dispose is not defined\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/compiler/factory/emitHelpers.ts","lineNumber":1394,"sourceCode":"                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\n/**\r\n * The `s` variable represents two boolean flags from the `DisposeResources` algorithm:\r\n * - `needsAwait` (`1`) — Indicates that an `await using` for a `null` or `undefined` resource was encountered.\r\n * - `hasAwaited` (`2`) — Indicates that the algorithm has performed an Await.\r","sourceCodeStart":1376,"sourceCodeEnd":1412,"githubUrl":"https://github.com/microsoft/TypeScript/blob/b465fdbfe175304d9b977da137b2c178ae1091d3/src/compiler/factory/emitHelpers.ts#L1376-L1412","documentation":"Runtime TypeError from `__addDisposableResource`. After the async path (or when not async), if no disposer was found via `Symbol.asyncDispose`, the helper falls back to `Symbol.dispose`; if that symbol is missing it throws. Thrown for both plain `using` and `await using` (as the fallback) when the runtime lacks the symbol.","triggerScenarios":"`using x = obj` (or `await using` where asyncDispose was absent) compiled with the downlevel helper, run on a runtime without `Symbol.dispose`. Reached before the per-object disposer is read, so even a correct `[Symbol.dispose]` method does not help if the symbol itself is undefined.","commonSituations":"Old Node.js/browsers; bundles with a low `target`; SSR/edge runtimes that omit the symbol; code that runs in multiple environments where only some are polyfilled.","solutions":["Polyfill `Symbol.dispose` at app entry (`(Symbol as any).dispose ??= Symbol(\"Symbol.dispose\")`).","Upgrade the runtime to one that ships `Symbol.dispose`.","Raise `target` so the helper is not emitted (native `using` on a supporting runtime).","If both dispose symbols are polyfilled, ensure the polyfill runs before any module that uses `using`."],"exampleFix":"// before: using transpiled on a runtime without Symbol.dispose -> TypeError\n// after:\n(Symbol as any).dispose ??= Symbol(\"Symbol.dispose\");\nusing r = openResource();","handlingStrategy":"validation","validationCode":"if ((Symbol as any).dispose === undefined) {\n  (Symbol as any).dispose = Symbol(\"Symbol.dispose\");\n}","typeGuard":"function hasDispose(): boolean { return (Symbol as any).dispose !== undefined; }","tryCatchPattern":null,"preventionTips":["Polyfill `Symbol.dispose` early when downleveling `using`.","Set `target`/`lib` consistently with the runtimes you ship to.","Run polyfills before any module body that uses `using`/`await using`."],"tags":["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"}