diff --git a/src/mods/box/box.ts b/src/mods/box/box.ts index 40b910d..80145f4 100644 --- a/src/mods/box/box.ts +++ b/src/mods/box/box.ts @@ -9,7 +9,11 @@ export class BoxMovedError extends Error { } } -export class Box implements Disposable { +export interface MaybeDisposable { + [Symbol.dispose]?: () => void +} + +export class Box implements Disposable { moved = false @@ -23,7 +27,7 @@ export class Box implements Disposable { [Symbol.dispose]() { if (this.moved) return - this.inner[Symbol.dispose]() + this.inner[Symbol.dispose]?.() } /** diff --git a/src/mods/copy/copy.ts b/src/mods/copy/copy.ts index 3e21452..e4c948c 100644 --- a/src/mods/copy/copy.ts +++ b/src/mods/copy/copy.ts @@ -1,6 +1,6 @@ export type BytesOrCopiable = - | Uint8Array & { length: N } - | Copiable + | Uint8Array & { readonly length: N } + | Copiable /** * An object whose bytes can be copied diff --git a/src/mods/slot/slot.ts b/src/mods/slot/slot.ts index 667eb60..68928f2 100644 --- a/src/mods/slot/slot.ts +++ b/src/mods/slot/slot.ts @@ -1,14 +1,16 @@ +import { MaybeDisposable } from "index.js" + /** * A disposable whose reference can change */ -export class Slot implements Disposable { +export class Slot implements Disposable { constructor( public inner: T ) { } [Symbol.dispose]() { - this.inner[Symbol.dispose]() + this.inner[Symbol.dispose]?.() } static new(inner: T) {