Skip to main content

Result

A Result represents a successful value or an error. It forces the consumer to check whether the returned type is an error or not, result.ok acts as a discriminant between success and failure.

For example, when processing the return type for the chat function you can do the following

const chatResult = chat(chatOptions);

if (!chatResult.ok) {
handleError(chatResult.error);

return;
}

console.log(chatResult.value.message)

The library never throws when there's an error, instead it returns an error result, and the value of the result (i.e. result.error) will be a request error.

Result type

Signature:

type Result<T, E> = OkResult<T> | ErrResult<E>;

References: OkResult, ErrResult

OkResult

Represents a successful result where you can access value

Signature:

interface OkResult<T> 

Properties

PropertyTypeDescription
oktrue
valueT

ErrResult

Represents a failure result

Signature:

interface ErrResult<E> 

Properties

PropertyTypeDescription
errorEUsually a request error
okfalse
Was this helpful?