@swizzyweb/swizzy-web-service
Version:
Web service framework for swizzy dyn serve
31 lines (30 loc) • 909 B
TypeScript
export type AssertMessageGenerator<T> = (args: T) => string;
/**
* Props for performing assertions that throw.
* <T> - args for evaluation
*/
export interface AssertOrThrowProps<ARGS> {
/**
* Args to use in assertion.
*/
args: ARGS;
/**
* Assertion function that performs assertion.
* @param args
* @returns if assertion passed
*/
assertion: (args: ARGS) => boolean;
/**
* Error message function or string to be included
* in thrown exception.
* @param args of assert for generating message
* @returns error message to include in assertion exception
*/
errorMessage?: AssertMessageGenerator<ARGS> | string;
}
/**
* Asserts the assertion is true, else throws with provided
* message or default message.
* @param props for performing assertion
*/
export declare function assertOrThrow<T>(props: AssertOrThrowProps<T>): void;