Type Definitions
Reference for core types in go-errors.
Type Definitions
This page provides a concise reference for the core types used in go-errors
.
Result<T, E>
The fundamental type representing the result of an operation that can either succeed or fail.
type Result<T, E = Error> = readonly [T, null] | readonly [null, E];
T
: The type of the successful value.E
: The type of the error (defaults toError
).
Possible Values:
[value, null]
: Represents a successful operation, wherevalue
is of typeT
.[null, error]
: Represents a failed operation, whereerror
is of typeE
.
Readonly: The tuple is readonly
to prevent accidental modification.
Example:
import { goSync } from 'go-errors';
let [result, err] = goSync(() => 42); // Result<number, Error>
GoFetchOptions<T, E>
Extends the standard RequestInit
interface with options specific to goFetch
.
interface GoFetchOptions<T, E = Error> extends RequestInit {
responseTransformer?: (data: unknown) => T;
errorTransformer?: (error: unknown) => E;
}
responseTransformer?: (data: unknown) => T
: Transforms the raw response data into the desired typeT
.errorTransformer?: (error: unknown) => E
: Transforms any error encountered during the fetch operation into the desired error typeE
.
Inherits all properties from RequestInit
, such as method
, headers
, body
, etc.