throw-expression
Version:
Allows you, through a simple function, to throw an error inside an expression
36 lines (35 loc) • 1.49 kB
TypeScript
/**
* Throws an error when called
* @param error either error object or a string
*/
export declare const Throw: (error: string | Error) => never;
/**
* Throw exception if value is null
* @param value value to be checked for null
* @param error either error object or a string
*/
export declare const throwIfNull: <T>(value: T | null, error?: string | Error) => T;
/**
* Throw exception if value is undefined
* @param value value to be checked for undefined
* @param error either error object or a string
*/
export declare const throwIfUndefined: <T>(value: T | undefined, error?: string | Error) => T;
/**
* Throw exception if value is falsy: empty string, zero, false, NaN, undefined or null
* @param value value to be checked for falsy: empty string, zero, false, NaN, undefined or null
* @param error either error object or a string
*/
export declare const throwIfFalsy: <T>(value: false | "" | 0 | T, error?: string | Error) => NonNullable<T>;
/**
* Throw exception if value is NaN, or not a number at all
* @param value value to be checked for NaN or not a number at all
* @param error either error object or a string
*/
export declare const throwIfNotANumber: <T>(value: T, error?: string | Error) => number;
/**
* Throw expression if value is null or undefined
* @param value to be checked for null or undefined
* @param error either error object or a string
*/
export declare const throwIfNullish: <T>(value: T, error?: string | Error) => NonNullable<T>;