@leancodepl/utils
Version:
Common utility functions and React hooks for web applications
18 lines (17 loc) • 751 B
TypeScript
/**
* Asserts that a value is not null or undefined. Throws an error if the value is null or undefined.
* This is a type assertion function that narrows the type to exclude null and undefined.
*
* @template T - The type of the value being checked
* @param value - The value to check for null or undefined
* @param message - Optional error message to use if assertion fails
* @throws {Error} When the value is null or undefined
* @example
* ```typescript
* function processOptionalData(data?: string | null) {
* assertNotEmpty(data);
* return data.toUpperCase(); // TypeScript knows data is not null/undefined
* }
* ```
*/
export declare function assertNotEmpty<T>(value: T | null | undefined, message?: string): asserts value is T;