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

  1. Polyfill `Symbol.asyncDispose` before any `await using` runs (`(Symbol as any).asyncDispose ??= Symbol("Symbol.asyncDispose")`).
  2. Raise the runtime / Node version to one that ships `Symbol.asyncDispose`.
  3. Switch the binding to plain `using` (with `Symbol.dispose`) if async disposal is not required.
  4. 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

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


AI-assisted analysis of microsoft/TypeScript@b465fdbfe1 (2026-08-12). Data as JSON: /api/errors/29e5337f0aa10db4. Report an issue: GitHub.