errgo-ts
Version:
A lightweight error handling library inspired by Go and Rust.
14 lines (13 loc) • 406 B
TypeScript
/**
* Ensures an unknown value is an `Error` instance, converting it if needed.
*
* @param e - unknown value to treat as an error.
* @returns `e` unchanged if already an Error, otherwise converts `e` to an Error.
*
* @example
* } catch (e: unknown) {
* // err is guaranteed to be an Error instance
* const err = coerceError(e);
* }
*/
export declare function coerceError(e: unknown): Error;