Overview
Type guard method that checks if aResult is an Ok variant. Returns true if the Result contains a success value.
Signature
boolean - true if the Result is Ok, false if it’s Err
Usage
Basic type checking
Type narrowing
Early returns
Filtering arrays
Type guard behavior
isOk() is a TypeScript type guard. After checking isOk(), TypeScript automatically narrows the type to Ok<T, E>, giving you access to .value.Comparison with other patterns
isOk vs match
isOk vs unwrapOr
When to use
- ✅ When you need different logic for success vs failure
- ✅ When integrating with existing imperative code
- ✅ When you need to access both
.valueand.errorin different branches - ❌ When you just need the value → use
unwrapOr()instead - ❌ When transforming results → use
map()orandThen()instead
Related
isErr
Check if Result is an Err variant
match
Pattern match on both variants