microsoft/TypeScript · error · TypeError
Symbol.asyncDispose is not defined.
Error message
Symbol.asyncDispose is not defined.
What it means
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.
Source
Thrown at src/compiler/factory/emitHelpers.ts:1390
scoped: false,
text: `
var __classPrivateFieldIn = (this && this.__classPrivateFieldIn) || function(state, receiver) {
if (receiver === null || (typeof receiver !== "object" && typeof receiver !== "function")) throw new TypeError("Cannot use 'in' operator on non-object");
return typeof state === "function" ? receiver === state : state.has(receiver);
};`,
};
const addDisposableResourceHelper: UnscopedEmitHelper = {
name: "typescript:addDisposableResource",
importName: "__addDisposableResource",
scoped: false,
text: `
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
if (value !== null && value !== void 0) {
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
var dispose, inner;
if (async) {
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
dispose = value[Symbol.asyncDispose];
}
if (dispose === void 0) {
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
dispose = value[Symbol.dispose];
if (async) inner = dispose;
}
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
env.stack.push({ value: value, dispose: dispose, async: async });
}
else if (async) {
env.stack.push({ async: true });
}
return value;
};`,
};
View on GitHub (pinned to b465fdbfe1)
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.
Example fix
// before: await using transpiled on an old runtime -> TypeError
// after: polyfill before use
(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose");
await using r = openAsyncResource(); Defensive patterns
Strategy: validation
Validate before calling
// Feature-detect and polyfill before binding with `await using`:
if ((Symbol as any).asyncDispose === undefined) {
(Symbol as any).asyncDispose = Symbol("Symbol.asyncDispose");
} Type guard
function hasAsyncDispose(): boolean { return (Symbol as any).asyncDispose !== undefined; } Prevention
- 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.
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- Symbol.dispose is not defined.
- Object expected.
- Object not disposable.
- Symbol.asyncIterator is not defined.
- Symbol.iterator is not defined.
AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12).
Data as JSON: /api/errors/29e5337f0aa10db4.
Report an issue: GitHub.