Overview
Result<T, E> is a discriminated union type representing the outcome of an operation that can either succeed with a value of type T or fail with an error of type E.
Type Structure
The Result type is a union of two variants:Ok<T, E>- Represents success with a value of typeTErr<T, E>- Represents failure with an error of typeE
Ok<T, E>:Tis the actual value type,Eis a phantom (unused at runtime)Err<T, E>:Tis a phantom (unused at runtime),Eis the actual error type
Result.gen().
The Ok Variant
Properties
"ok"
required
Discriminant property that identifies this as a success result
A
required
The success value
The Err Variant
Properties
"error"
required
Discriminant property that identifies this as an error result
E
required
The error value
Type Utilities
InferOk
Extracts the success type from a Result:InferErr
Extracts the error type from a Result:Discriminated Union Pattern
The Result type uses TypeScript’s discriminated union feature via thestatus property: