Skip to content

right

Builds an EitherRight by associating mandatory business information (literal string) and an optional payload. This is the basic brick to signal a contextualized success.

Interactive example

Syntax

typescript
function right<
	GenericInformation extends string, 
	const GenericInput extends unknown = undefined
>(
  information: GenericInformation,
  value?: GenericInput
): EitherRight<GenericInformation, GenericInput>

Parameters

  • information: Literal string that precisely describes the success (e.g., "user.created"). This information stays in the type.
  • input: Optional payload associated with the success. If omitted, the inferred type becomes undefined.

Return value

An EitherRight<Information, Value> that can be discriminated with E.isRight, E.hasInformation, or E.whenHasInformation.

Best practices

  • Get used to descriptive strings ("user.created", "invoice.validated") to simplify pattern matching.
  • Do not share the same strings between several different business cases.
  • Combine right with left so every branch of a function returns a homogeneous Either.

See also

  • success – Specialized shortcut for right("success", value).
  • ok – Payload-less variant (Right<"ok">).
  • hasInformation – Type guard on business information.

Released under the MIT license.