shelving
Version:
Toolkit for using data in JavaScript.
18 lines (17 loc) • 1.26 kB
TypeScript
import type { Arguments } from "./function.js";
/** Class that has a public `constructor()` function. */
export type Constructor<T, A extends Arguments> = new (...args: A) => T;
/** Any function arguments (designed for use with `extends Arguments` guards). */
export type AnyConstructor = new (...args: any) => any;
/** Class prototype that can be used with `instanceof`. */
export type Class<T> = new (...args: any) => T;
/** Is a given value a class constructor? */
export declare function isConstructor(value: unknown): value is AnyConstructor;
/** Is a value an instance of a class? */
export declare function isInstance<T>(value: unknown, type: Class<T>): value is T;
/** Assert that a value is an instance of something. */
export declare function assertInstance<T>(value: unknown, type: Class<T>): asserts value is T;
/** Get the 'getter' function for a given property, or `undefined` if it doesn't exist. */
export declare function getGetter<T extends Object, K extends keyof T>(obj: T, prop: K): ((this: T) => T[K]) | undefined;
/** Get the 'setter' function for a given property, or `undefined` if it doesn't exist. */
export declare function getSetter<T extends Object, K extends keyof T>(obj: T, prop: K): ((this: T, value: T[K]) => void) | undefined;