UNPKG

@leancodepl/utils

Version:

Common utility functions and React hooks for web applications

18 lines (17 loc) 746 B
/** * Ensures that a value is not null or undefined, returning it if valid or throwing an error if empty. * * @template T - The type of the value being checked * @param value - The value to ensure is not null or undefined * @param message - Optional error message to use if the value is null or undefined * @returns The value if it is not null or undefined * @throws {Error} When the value is null or undefined * @example * ```typescript * function processOptionalData(data?: string | null) { * const validData = ensureNotEmpty(data); * return validData.toUpperCase(); // validData is guaranteed to be not null/undefined * } * ``` */ export declare function ensureNotEmpty<T>(value: T | null | undefined, message?: string): T;