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: PotentiallyEithervalue. 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
isRightwithE.hasInformationto target a specific success. - Use it as a first guard to secure an
unwrap. - In a functional flow,
isRightcan be passed towhenElseorfilterto separate successes from errors.
See also
whenIsRight– Executes a callback only when the input isRight.isLeft–Leftcounterpart.
