export function isPromise(obj: unknown): obj is Promise { return Boolean(obj) && typeof (obj as Promise).then === "function"; } export function isWeakMapKey(value: unknown): value is object { return (typeof value === "object" && value !== null) || typeof value === "function"; } export function resolveCallable( instance: This, input: ((...args: any[]) => Return) | keyof This, ): (...args: any[]) => Return { if (typeof input === "function") { return input.bind(instance); } const resolved = (instance as Record)[input as PropertyKey]; if (typeof resolved !== "function") { throw new TypeError(`Expected ${String(input)} to resolve to a function.`); } return resolved.bind(instance) as (...args: any[]) => Return; } export function sleep(ms: number): Promise { return new Promise((resolve) => { setTimeout(resolve, ms); }); }