Skip to content

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: Potentially Either value. Can be a Left | Right union.

Return value

true when the input is an EitherLeft. The type is then narrowed to include only the Left part.

Best practices

  • Use isLeft before reading the encapsulated value on the error side.
  • Combine it with E.hasInformation to target a specific business error.
  • In pipelines, isLeft can be passed to whenElse to short-circuit on the first error.

See also

  • isRight – Success-side counterpart.
  • whenIsLeft – Functional version with callback.

Released under the MIT license.