Utilities
Functions
Section titled “Functions”createTypedEventTarget()
Section titled “createTypedEventTarget()”function createTypedEventTarget<T>(): TypedEventTarget<T>Defined in: utils/typed-event-target.ts:37
Create a new TypedEventTarget<T> for a given event map. Centralises the
EventTarget → TypedEventTarget<T> cast so individual call sites don’t
each need their own (EventTarget lacks the generic event map at the type
level, but the runtime behaviour is identical).
Type Parameters
Section titled “Type Parameters”T extends EventMap
Returns
Section titled “Returns”getTransferableObjects()
Section titled “getTransferableObjects()”Guide: Low-level API
function getTransferableObjects(value: unknown): Transferable[]Defined in: utils/transferable.ts:33
Walk a boxed message and collect Transferables to move (rather than copy) on postMessage:
- Must-transfer types are always included.
- Clonable types (SharedArrayBuffer) are skipped.
- Other Transferables are included only inside a non-degraded transfer box (user opted in AND the platform supports transferring).
Parameters
Section titled “Parameters”unknown
Returns
Section titled “Returns”Transferable[]
isTornDown()
Section titled “isTornDown()”function isTornDown(scope: WeakKey): booleanDefined in: utils/teardown.ts:23
Whether a scope’s teardown has already run. Callers use this to REFUSE work rather than start it:
onTeardown against a dead scope runs the callback immediately, which is a footgun inside an
initializer, and anything registered afterwards is state no teardown will ever visit again.
Parameters
Section titled “Parameters”WeakKey
Returns
Section titled “Returns”boolean
onTeardown()
Section titled “onTeardown()”function onTeardown(scope: WeakKey, fn: () => void): () => voidDefined in: utils/teardown.ts:9
Parameters
Section titled “Parameters”WeakKey
() => void
Returns
Section titled “Returns”() => void
trackGc()
Section titled “trackGc()”function trackGc(target: WeakKey, cleanup: () => void): GcUnregisterDefined in: utils/gc-tracker.ts:25
Parameters
Section titled “Parameters”target
Section titled “target”WeakKey
cleanup
Section titled “cleanup”() => void
Returns
Section titled “Returns”Classes
Section titled “Classes”EventChannel
Section titled “EventChannel”Defined in: utils/event-channel.ts:130
Type Parameters
Section titled “Type Parameters”T1 = unknown
T2 = unknown
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EventChannel<T1, T2>(): EventChannel<T1, T2>;Defined in: utils/event-channel.ts:134
Returns
Section titled “Returns”EventChannel<T1, T2>
Properties
Section titled “Properties”readonly port1: EventPort<T1>;Defined in: utils/event-channel.ts:131
readonly port2: EventPort<T2>;Defined in: utils/event-channel.ts:132
EventPort
Section titled “EventPort”Defined in: utils/event-channel.ts:6
Extends
Section titled “Extends”Omit<TypedMessagePort<T>,"addEventListener"|"removeEventListener">
Type Parameters
Section titled “Type Parameters”T
Accessors
Section titled “Accessors”onmessage
Section titled “onmessage”Get Signature
Section titled “Get Signature”get onmessage(): | ((this: MessagePort, ev: MessageEvent<T>) => unknown) | null;Defined in: utils/event-channel.ts:60
Returns
Section titled “Returns”| ((this: MessagePort, ev: MessageEvent<T>) => unknown)
| null
Set Signature
Section titled “Set Signature”set onmessage(value: | ((this: MessagePort, ev: MessageEvent<T>) => unknown) | null): void;Defined in: utils/event-channel.ts:63
Parameters
Section titled “Parameters”| ((this: MessagePort, ev: MessageEvent<T>) => unknown)
| null
Returns
Section titled “Returns”void
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new EventPort<T>(): EventPort<T>;Returns
Section titled “Returns”EventPort<T>
Methods
Section titled “Methods”addEventListener()
Section titled “addEventListener()”Call Signature
Section titled “Call Signature”addEventListener<K>( type: K, listener: | ((event: TypedMessagePortEventMap<T>[K]) => void) | null, options?: boolean | AddEventListenerOptions): void;Defined in: utils/event-channel.ts:10
Type Parameters
Section titled “Type Parameters”K extends "close" | "message" | "messageerror"
Parameters
Section titled “Parameters”K
listener
Section titled “listener”| ((event: TypedMessagePortEventMap<T>[K]) => void)
| null
options?
Section titled “options?”boolean | AddEventListenerOptions
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”addEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;Defined in: utils/event-channel.ts:15
Parameters
Section titled “Parameters”string
listener
Section titled “listener”EventListenerOrEventListenerObject | null
options?
Section titled “options?”boolean | AddEventListenerOptions
Returns
Section titled “Returns”void
close()
Section titled “close()”close(): void;Defined in: utils/event-channel.ts:109
Returns
Section titled “Returns”void
dispatchEvent()
Section titled “dispatchEvent()”dispatchEvent(event: Event): boolean;Defined in: utils/event-channel.ts:70
Parameters
Section titled “Parameters”Event
Returns
Section titled “Returns”boolean
postMessage()
Section titled “postMessage()”postMessage(message: T, _options?: Transferable[] | StructuredSerializeOptions): void;Defined in: utils/event-channel.ts:87
Parameters
Section titled “Parameters”message
Section titled “message”T
_options?
Section titled “_options?”Transferable[] | StructuredSerializeOptions
Returns
Section titled “Returns”void
removeEventListener()
Section titled “removeEventListener()”Call Signature
Section titled “Call Signature”removeEventListener<K>( type: K, listener: | ((event: TypedMessagePortEventMap<T>[K]) => void) | null, options?: boolean | EventListenerOptions): void;Defined in: utils/event-channel.ts:33
Type Parameters
Section titled “Type Parameters”K extends "close" | "message" | "messageerror"
Parameters
Section titled “Parameters”K
listener
Section titled “listener”| ((event: TypedMessagePortEventMap<T>[K]) => void)
| null
options?
Section titled “options?”boolean | EventListenerOptions
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”removeEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;Defined in: utils/event-channel.ts:38
Parameters
Section titled “Parameters”string
listener
Section titled “listener”EventListenerOrEventListenerObject | null
options?
Section titled “options?”boolean | EventListenerOptions
Returns
Section titled “Returns”void
start()
Section titled “start()”start(): void;Defined in: utils/event-channel.ts:101
Returns
Section titled “Returns”void
Properties
Section titled “Properties”_closed
Section titled “_closed”_closed: boolean = falseDefined in: utils/event-channel.ts:55
_onClose
Section titled “_onClose”_onClose: (() => void) | undefined;Defined in: utils/event-channel.ts:56
_peer: EventPort<any> | undefinedDefined in: utils/event-channel.ts:52
_queue
Section titled “_queue”_queue: MessageEvent<T>[] = [];Defined in: utils/event-channel.ts:53
_started
Section titled “_started”_started: boolean = falseDefined in: utils/event-channel.ts:54
[UnderlyingType]?
Section titled “[UnderlyingType]?”optional [UnderlyingType]?: T;Defined in: utils/typed-message-channel.ts:15
onmessageerror
Section titled “onmessageerror”onmessageerror: ((this: MessagePort, ev: MessageEvent) => unknown) | null = null;Defined in: utils/event-channel.ts:68
Interfaces
Section titled “Interfaces”TypedEventTarget
Section titled “TypedEventTarget”Defined in: utils/typed-event-target.ts:5
Extends
Section titled “Extends”EventTarget
Type Parameters
Section titled “Type Parameters”T extends EventMap
Methods
Section titled “Methods”addEventListener()
Section titled “addEventListener()”Call Signature
Section titled “Call Signature”addEventListener<K>( type: K, listener: ((event: T[K]) => void) | null, options?: boolean | AddEventListenerOptions): void;Defined in: utils/typed-event-target.ts:8
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
listener
Section titled “listener”((event: T[K]) => void) | null
options?
Section titled “options?”boolean | AddEventListenerOptions
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”EventTarget.addEventListenerCall Signature
Section titled “Call Signature”addEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;Defined in: utils/typed-event-target.ts:13
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Parameters
Section titled “Parameters”string
listener
Section titled “listener”EventListenerOrEventListenerObject | null
options?
Section titled “options?”boolean | AddEventListenerOptions
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”EventTarget.addEventListenerremoveEventListener()
Section titled “removeEventListener()”Call Signature
Section titled “Call Signature”removeEventListener<K>( type: K, listener: ((event: T[K]) => void) | null, options?: boolean | EventListenerOptions): void;Defined in: utils/typed-event-target.ts:19
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
Type Parameters
Section titled “Type Parameters”K extends string
Parameters
Section titled “Parameters”K
listener
Section titled “listener”((event: T[K]) => void) | null
options?
Section titled “options?”boolean | EventListenerOptions
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”EventTarget.removeEventListenerCall Signature
Section titled “Call Signature”removeEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;Defined in: utils/typed-event-target.ts:24
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
Parameters
Section titled “Parameters”string
listener
Section titled “listener”EventListenerOrEventListenerObject | null
options?
Section titled “options?”boolean | EventListenerOptions
Returns
Section titled “Returns”void
Overrides
Section titled “Overrides”EventTarget.removeEventListenerProperties
Section titled “Properties”[UnderlyingType]?
Section titled “[UnderlyingType]?”optional [UnderlyingType]?: T;Defined in: utils/typed-event-target.ts:6
TypedMessageChannel
Section titled “TypedMessageChannel”Defined in: utils/typed-message-channel.ts:27
Type Parameters
Section titled “Type Parameters”T1 = unknown
T2 = unknown
Properties
Section titled “Properties”readonly port1: TypedMessagePort<T1>;Defined in: utils/typed-message-channel.ts:28
readonly port2: TypedMessagePort<T2>;Defined in: utils/typed-message-channel.ts:29
TypedMessagePort
Section titled “TypedMessagePort”Defined in: utils/typed-message-channel.ts:10
Extends
Section titled “Extends”Omit<TypedEventTarget<TypedMessagePortEventMap<T>>, typeofUnderlyingType>
Type Parameters
Section titled “Type Parameters”T = unknown
Methods
Section titled “Methods”addEventListener()
Section titled “addEventListener()”Call Signature
Section titled “Call Signature”addEventListener<K>( type: K, listener: | ((event: TypedMessagePortEventMap<T>[K]) => void) | null, options?: boolean | AddEventListenerOptions): void;Defined in: utils/typed-event-target.ts:8
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Type Parameters
Section titled “Type Parameters”K extends "close" | "message" | "messageerror"
Parameters
Section titled “Parameters”K
listener
Section titled “listener”| ((event: TypedMessagePortEventMap<T>[K]) => void)
| null
options?
Section titled “options?”boolean | AddEventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.addEventListenerCall Signature
Section titled “Call Signature”addEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | AddEventListenerOptions): void;Defined in: utils/typed-event-target.ts:13
The addEventListener() method of the EventTarget interface sets up a function that will be called whenever the specified event is delivered to the target.
Parameters
Section titled “Parameters”string
listener
Section titled “listener”EventListenerOrEventListenerObject | null
options?
Section titled “options?”boolean | AddEventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.addEventListenerclose()
Section titled “close()”close(): void;Defined in: utils/typed-message-channel.ts:24
Returns
Section titled “Returns”void
postMessage()
Section titled “postMessage()”Call Signature
Section titled “Call Signature”postMessage(message: T, transfer: Transferable[]): void;Defined in: utils/typed-message-channel.ts:20
Parameters
Section titled “Parameters”message
Section titled “message”T
transfer
Section titled “transfer”Transferable[]
Returns
Section titled “Returns”void
Call Signature
Section titled “Call Signature”postMessage(message: T, options?: StructuredSerializeOptions): void;Defined in: utils/typed-message-channel.ts:21
Parameters
Section titled “Parameters”message
Section titled “message”T
options?
Section titled “options?”StructuredSerializeOptions
Returns
Section titled “Returns”void
removeEventListener()
Section titled “removeEventListener()”Call Signature
Section titled “Call Signature”removeEventListener<K>( type: K, listener: | ((event: TypedMessagePortEventMap<T>[K]) => void) | null, options?: boolean | EventListenerOptions): void;Defined in: utils/typed-event-target.ts:19
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
Type Parameters
Section titled “Type Parameters”K extends "close" | "message" | "messageerror"
Parameters
Section titled “Parameters”K
listener
Section titled “listener”| ((event: TypedMessagePortEventMap<T>[K]) => void)
| null
options?
Section titled “options?”boolean | EventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.removeEventListenerCall Signature
Section titled “Call Signature”removeEventListener( type: string, listener: EventListenerOrEventListenerObject | null, options?: boolean | EventListenerOptions): void;Defined in: utils/typed-event-target.ts:24
The removeEventListener() method of the EventTarget interface removes an event listener previously registered with EventTarget.addEventListener() from the target. The event listener to be removed is identified using a combination of the event type, the event listener function itself, and various optional options that may affect the matching process; see Matching event listeners for removal.
Parameters
Section titled “Parameters”string
listener
Section titled “listener”EventListenerOrEventListenerObject | null
options?
Section titled “options?”boolean | EventListenerOptions
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”Omit.removeEventListenerstart()
Section titled “start()”start(): void;Defined in: utils/typed-message-channel.ts:23
Returns
Section titled “Returns”void
Properties
Section titled “Properties”[UnderlyingType]?
Section titled “[UnderlyingType]?”optional [UnderlyingType]?: T;Defined in: utils/typed-message-channel.ts:15
onmessage
Section titled “onmessage”onmessage: | ((this: MessagePort, ev: MessageEvent<T>) => unknown) | null;Defined in: utils/typed-message-channel.ts:17
onmessageerror
Section titled “onmessageerror”onmessageerror: ((this: MessagePort, ev: MessageEvent) => unknown) | nullDefined in: utils/typed-message-channel.ts:18
Type Aliases
Section titled “Type Aliases”BadFieldParent
Section titled “BadFieldParent”type BadFieldParent<T, TConstraint> = FindBadField<T, TConstraint> extends { parent: infer P } ? P : TDefined in: utils/capable-check.ts:62
The immediate parent object/array containing the first non-conforming
value. Equals T when the root itself fails.
Type Parameters
Section titled “Type Parameters”T
TConstraint
Section titled “TConstraint”TConstraint
BadFieldPath
Section titled “BadFieldPath”type BadFieldPath<T, TConstraint> = FindBadField<T, TConstraint> extends { path: infer P } ? P : ''Defined in: utils/capable-check.ts:55
Dotted/bracketed path to the first non-conforming value (e.g. "a.b[2]").
Empty string if the root itself fails the check.
Type Parameters
Section titled “Type Parameters”T
TConstraint
Section titled “TConstraint”TConstraint
BadFieldValue
Section titled “BadFieldValue”type BadFieldValue<T, TConstraint> = FindBadField<T, TConstraint> extends { value: infer V } ? V : TDefined in: utils/capable-check.ts:48
The first non-conforming value found by deep traversal of T against
TConstraint. Falls back to T if no traversal is applicable.
Type Parameters
Section titled “Type Parameters”T
TConstraint
Section titled “TConstraint”TConstraint
DeepReplaceWithBox
Section titled “DeepReplaceWithBox”type DeepReplaceWithBox<T, M> = [FindMatchingBox<T, M>] extends [never] ? T extends infer U[] ? DeepReplaceWithBox<U, M>[] : T extends object ? { [K in keyof T]: DeepReplaceWithBox<T[K], M> } : T : FindMatchingBox<T, M>;Defined in: utils/replace.ts:11
Type Parameters
Section titled “Type Parameters”T
M
DeepReplaceWithRevive
Section titled “DeepReplaceWithRevive”type DeepReplaceWithRevive<T, M> = [FindMatchingRevive<T, M>] extends [never] ? T extends infer U[] ? DeepReplaceWithRevive<U, M>[] : T extends object ? { [K in keyof T]: DeepReplaceWithRevive<T[K], M> } : T : FindMatchingRevive<T, M>;Defined in: utils/replace.ts:23
Type Parameters
Section titled “Type Parameters”T
M
EventMap
Section titled “EventMap”type EventMap = Record<string, Event>Defined in: utils/typed-event-target.ts:3
GcUnregister
Section titled “GcUnregister”type GcUnregister = () => voidDefined in: utils/gc-tracker.ts:18
Run cleanup after target is garbage-collected. Returns a handle to
cancel the tracking before that happens.
Backed by a single shared FinalizationRegistry - every revivable that needs FR semantics goes through this so the boilerplate (token, unregister, cycle-safety contract) lives in one place.
Contract: cleanup MUST NOT (transitively) reference target. The
registry strong-holds the cleanup callback, the cleanup would then
strong-hold target, and the engine would never see target as
collectable. Use a WeakRef if cleanup needs something that points
back at target.
Errors thrown from cleanup are swallowed: the callback fires from the FR thread, where there’s no caller to surface them to.
Returns
Section titled “Returns”void
ReplaceWithBox
Section titled “ReplaceWithBox”type ReplaceWithBox<T, M> = [FindMatchingBox<T, M>] extends [never] ? T : FindMatchingBox<T, M>Defined in: utils/replace.ts:6
Type Parameters
Section titled “Type Parameters”T
M
TypedMessagePortEventMap
Section titled “TypedMessagePortEventMap”type TypedMessagePortEventMap<T> = { close: Event message: MessageEvent<T> messageerror: MessageEvent}Defined in: utils/typed-message-channel.ts:4
Type Parameters
Section titled “Type Parameters”T = unknown
Properties
Section titled “Properties”close: EventDefined in: utils/typed-message-channel.ts:7
message
Section titled “message”message: MessageEvent<T>Defined in: utils/typed-message-channel.ts:5
messageerror
Section titled “messageerror”messageerror: MessageEventDefined in: utils/typed-message-channel.ts:6
UnderlyingType
Section titled “UnderlyingType”type UnderlyingType = typeof UnderlyingTypeDefined in: utils/type.ts:1
Variables
Section titled “Variables”BadValue
Section titled “BadValue”const BadValue: unique symbolDefined in: utils/capable-check.ts:2
ErrorMessage
Section titled “ErrorMessage”const ErrorMessage: unique symbolDefined in: utils/capable-check.ts:1
ParentObject
Section titled “ParentObject”const ParentObject: unique symbolDefined in: utils/capable-check.ts:4
const Path: unique symbolDefined in: utils/capable-check.ts:3
UnderlyingType
Section titled “UnderlyingType”const UnderlyingType: unique symbolDefined in: utils/type.ts:1