isLeft
Type guard that checks whether a value is an EitherLeft. 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, EitherLeft>Parameters
input: PotentiallyEithervalue. Can be aLeft | Rightunion.
Return value
true when the input is an EitherLeft. 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.
