Overview
Type guard method that checks if aResult is an Err variant. Returns true if the Result contains an error value.
Signature
boolean - true if the Result is Err, false if it’s Ok
Usage
Basic error checking
Type narrowing
Early error returns
Error recovery
Collecting errors
Type guard behavior
isErr() is a TypeScript type guard. After checking isErr(), TypeScript automatically narrows the type to Err<T, E>, giving you access to .error.Common patterns
Guard clause pattern
Negation pattern
Comparison with other patterns
isErr vs match
isErr vs mapErr
When to use
- ✅ When you need to handle errors immediately
- ✅ When using guard clauses for early returns
- ✅ When integrating with existing imperative code
- ✅ When collecting or filtering errors from arrays
- ❌ When transforming errors → use
mapErr()instead - ❌ When recovering from errors → use
orElse()instead
Related
isOk
Check if Result is an Ok variant
mapErr
Transform error values