shelving
Version:
Toolkit for using data in JavaScript.
10 lines (9 loc) • 615 B
TypeScript
import type { Class } from "./class.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): T;