happy-rusty
    Preparing search index...

    Type Alias AsyncResult<T, E>

    AsyncResult: Promise<Result<T, E>>

    Represents an asynchronous operation that yields a Result<T, E>. This is a promise that resolves to Ok(T) if the operation was successful, or Err(E) if there was an error.

    Type Parameters

    • T

      The type of the value that is produced by a successful operation.

    • E

      The type of the error that may be produced by a failed operation.

    1.5.0

    async function fetchUser(id: number): AsyncResult<User, Error> {
    try {
    const response = await fetch(`/users/${id}`);
    if (response.ok) {
    return Ok(await response.json());
    }
    return Err(new Error('User not found'));
    } catch (e) {
    return Err(e as Error);
    }
    }