shelving
Version:
Toolkit for using data in JavaScript.
11 lines (10 loc) • 683 B
TypeScript
import type { Class } from "./class.js";
import type { AnyCaller } from "./function.js";
/** Something that has a source of a specified type. */
export interface Sourceable<T> {
readonly source: T;
}
/** Recurse through `Sourceable` objects and return the first one that is an instance of `type`, or `undefined` if no source object matches. */
export declare function getSource<T>(type: Class<T>, value: unknown): T | undefined;
/** Recurse through `Sourceable` objects and return the first one that is an instance of `type`, or throw `RequiredError` if no source object matches. */
export declare function requireSource<T>(type: Class<T>, data: unknown, caller?: AnyCaller): T;