@vsokolov/utils - v0.32.0
    Preparing search index...

    Type Alias Result<T, E>

    Result: Success<T> | Failure<E>

    Result type representing either a success with data or a failure with error. This discriminated union enables type-safe error handling without try/catch blocks.

    Type Parameters

    • T

      The type of the successful data

    • E = ErrorWithStatus

      The type of the error, defaults to ErrorWithStatus

    const result: Result<string> = await tryCatch(fetchText());
    if (result.error) {
    // TypeScript knows result.data is null here
    console.error(result.error.message);
    } else {
    // TypeScript knows result.error is null here
    console.log(result.data.toUpperCase());
    }