Skip to content

Type Alias: DisposeKey

API / @xmachines/play / DisposeKey

type DisposeKey = SymbolConstructor extends object ? Key : never;

Defined in: packages/play/src/disposable.ts:34

The dispose key of the ambient library, and never where the consumer omits it.

Symbol.dispose and the Disposable interface arrive with lib.esnext.disposable. A consumer gets that library from "lib": ["ESNext"], and NOT from "lib": ["ES2022"] or ["ES2023"]. A published .d.ts that names either one therefore refuses to type-check for every consumer of the second kind, and this package cannot ask for the library on their behalf: TypeScript copies no /// <reference lib="..." /> into declaration output.

The conditional asks the compiler instead of naming the key. Where the library is present the key resolves to typeof Symbol.dispose, and Cleanup is a Disposable that a using declaration accepts. Where the library is absent the key resolves to never, the mapped type of Cleanup adds no member, and Cleanup IS the plain () => void that these functions returned before this protocol existed. That consumer loses nothing, because using is syntax that the same library gates: a compiler that cannot name Symbol.dispose cannot compile the form either.

The runtime is not involved. asCleanup stores the release under DISPOSE whatever the consumer declares, so one build serves both.

The type is exported because the published .d.ts names it, and a reader who asks why Cleanup carries no dispose member needs to reach the answer.