@monstermann/fn
Version:
A utility library for TypeScript.
27 lines (25 loc) • 646 B
TypeScript
import { NonNil } from "../internals/types.js";
//#region src/option/orThrow.d.ts
/**
* `orThrow(target)`
*
* Returns the target value if it's not `null` or `undefined`, otherwise throws an error. This function is useful for asserting that a value is not null or undefined.
*
* ```ts
* orThrow(5); // 5
* orThrow("hello"); // "hello"
* orThrow(null); // throws FnError
* orThrow(undefined); // throws FnError
* ```
*
* ```ts
* pipe(5, orThrow()); // 5
* pipe(null, orThrow()); // throws FnError
* ```
*/
declare const orThrow: {
<T>(): (target: T) => NonNil<T>;
<T>(target: T): NonNil<T>;
};
//#endregion
export { orThrow };