Skip to content

isRight

Type guard that checks whether a value is an EitherRight. Allows accessing the payload without explicit conversion.

Interactive example

Syntax

typescript
function isRight<
	GenericInput extends unknown
>(
  input: GenericInput
): input is Extract<GenericInput, EitherRight>

Parameters

  • input: Potentially Either value. The type can be a union.

Return value

true if the input is an EitherRight, false otherwise. Thanks to the type guard, TypeScript automatically narrows the type in each branch.

Best practices

  • Combine isRight with E.hasInformation to target a specific success.
  • Use it as a first guard to secure an unwrap.
  • In a functional flow, isRight can be passed to whenElse or filter to separate successes from errors.

See also

  • whenIsRight – Executes a callback only when the input is Right.
  • isLeftLeft counterpart.

Released under the MIT license.