Skip to content

Variable: DISPOSE

API / @xmachines/core / utils / DISPOSE

const DISPOSE: DisposeKey;

Defined in: packages/core/src/utils/disposable.ts:71

The key that a release is stored under.

Symbol.dispose where the runtime has it, and Symbol.for("Symbol.dispose") where it does not. This is not a convenience — it is the difference between a using that releases and one that raises.

A bundler that downlevels using for a target below Chrome 134 emits a helper that reads object[Symbol.dispose || Symbol.for("Symbol.dispose")]. A release stored under a bare [Symbol.dispose] lands on the string key "undefined" in that runtime, because the well-known symbol is absent and the computed key takes the value undefined. The helper then looks up the registered symbol, finds nothing, and throws TypeError: Object is not disposable. Storing under the same fallback closes the gap.

The type assertion states what the fallback IS. Symbol.for returns a plain symbol, TypeScript declares Symbol.dispose as a unique symbol, and no expression produces a unique symbol other than the declaration itself.

This binding resolves ONE time, when the module evaluates. asDisposable therefore reads Symbol.dispose again at each call, and it stores the release under both keys. A polyfill that installs the well-known symbol after this module evaluates still finds the release. A class or an object literal that writes [DISPOSE]() has no such second chance: it carries the key that existed when it was defined. Install an Explicit Resource Management polyfill before the first import of @xmachines/core/utils, which is the ordinary contract of a polyfill.