Skip to main content

Shared Contracts

Disposable

Lifecycle contract for resources that need explicit cleanup. Emits a disposed event when the resource is torn down.

interface Disposable {
isDisposed: boolean;
}

NamedClass

Common shape for classes that surface a display name in logs and telemetry.

interface NamedClass {
displayName?: string;
name: string;
}

Serializable

Shape implemented by types that can be serialised to JSON for transport or logging.

interface Serializable {
}

SourceProvider

Live source of values of type Source. Emits the canonical source event whenever the underlying value changes.

interface SourceProvider<Source = unknown> {
__events: object;
kind: string;
source: Source | literal;
}

DeepReadonly

Recursively applies readonly to every property of an object or array. Functions are returned unchanged.

type DeepReadonly<T> = conditional
unknown

DisposeFunction

Callback signature accepted by Disposable.dispose.

type DisposeFunction = object
unknown

Events

Extracts the event map from an IEventEmitter. Resolves to never when the supplied type is not an event emitter.

type Events<T> = conditional
unknown

Json

Recursive JSON value type. Allows primitives, arrays, plain records, and any value that exposes a toJSON() method.

type Json = string | number | boolean | literal | undefined | any | Json[] | object | object
string | number | boolean | unknown | undefined | any | Json[] | unknown | unknown

Merge

Intersection of up to three types. Used to merge an event-emitter interface with a Disposable surface and any third mixin.

type Merge<A, B, C = unknown> = intersection
unknown