Skip to content

unwrapByInformation

Unwraps an Either payload when one literal information or one of multiple literal informations matches, otherwise returns the original input unchanged.

Interactive example

Syntax

Classic signature

typescript
function unwrapByInformation<
  GenericInput extends unknown,
  GenericInformation extends (
    GenericInput extends Either
      ? ReturnType<typeof informationKind.getValue<GenericInput>>
      : never
  ),
>(
  input: GenericInput,
  information: GenericInformation | GenericInformation[],
): GenericInput extends Kind<typeof informationKind.definition, GenericInformation>
  ? Unwrap<GenericInput>
  : GenericInput

Curried signature

typescript
function unwrapByInformation<
  GenericInput extends unknown,
  const GenericInformation extends (
    GenericInput extends Either
      ? ReturnType<typeof informationKind.getValue<GenericInput>>
      : never
  ),
>(
  information: GenericInformation | GenericInformation[],
): (
  input: GenericInput,
) => GenericInput extends Kind<typeof informationKind.definition, GenericInformation>
  ? Unwrap<GenericInput>
  : GenericInput

Parameters

  • information: Expected literal information, or an array of literal informations.
  • input: Either value to unwrap immediately, or later through the curried form.

Return value

Returns the unwrapped payload when one information matches. If no information matches, returns the original input unchanged.

See also

Released under the MIT license.