isLeft
Type guard that checks whether a value is an Left. Ideal to secure an unwrap or trigger an error branch.
Interactive example
Syntax
typescript
function isLeft<
GenericInput extends unknown
>(
input: GenericInput
): input is Extract<GenericInput, Left>Parameters
input: PotentiallyEithervalue. Can be aLeft | Rightunion.
Return value
true when the input is an Left. The type is then narrowed to include only the Left part.
Best practices
- Use
isLeftbefore reading the encapsulated value on the error side. - Combine it with
E.hasInformationto target a specific business error. - In pipelines,
isLeftcan be passed towhenElseto short-circuit on the first error.
See also
isRight– Success-side counterpart.whenIsLeft– Functional version with callback.
