Skip to content

isRight ​

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

Interactive example ​

Syntax ​

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

Parameters ​

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

Return value ​

true if the input is an Right, 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.
  • isLeft – Left counterpart.

Released under the MIT license.