UNPKG

@pho9ubenaa/remark-mask-text-beta

Version:

A remark plugin to mask text content with block characters

58 lines (57 loc) 1.68 kB
/** * Result type for error handling following functional programming principles * * This type represents the outcome of operations that may fail, providing * a type-safe way to handle errors without throwing exceptions. This approach * improves code reliability and makes error paths explicit. * * Why (Business Logic Background): * - Functional programming performs explicit error handling without throwing exceptions * - Result type forces callers to handle errors explicitly * - TypeScript's type system enforces error paths and prevents bugs proactively * - Provides consistent error handling patterns for async operations and complex transformations * * @template T - The type of successful result data * @template E - The type of error information */ export type Result<T, E> = { /** * Indicates successful operation */ ok: true; /** * The successful result data */ data: T; } | { /** * Indicates failed operation */ ok: false; /** * The error information */ error: E; }; /** * Type guard for successful Result * * Why (Business Logic Background): * - Ensure TypeScript's Discriminated Union type inference * - Guarantee compile-time type safety and prevent runtime errors */ export declare const isSuccess: <T, E>(result: Result<T, E>) => result is { ok: true; data: T; }; /** * Type guard for failed Result * * Why (Business Logic Background): * - Guarantee type safety during error handling * - Enable early bug detection through explicit error checking */ export declare const isFailure: <T, E>(result: Result<T, E>) => result is { ok: false; error: E; };