UNPKG

@leancodepl/utils

Version:

Common utility functions and React hooks for web applications

18 lines (17 loc) 654 B
/** * Ensures that a value is defined, returning it if defined or throwing an error if undefined. * * @template T - The type of the value being checked * @param value - The value to ensure is defined * @param message - Optional error message to use if the value is undefined * @returns The value if it is defined * @throws {Error} When the value is undefined * @example * ```typescript * function processUser(user?: User) { * const definedUser = ensureDefined(user); * return definedUser.name; // definedUser is guaranteed to be defined * } * ``` */ export declare function ensureDefined<T>(value: T | undefined, message?: string): T;