unwrapByInformationOrThrow
Unwraps an Either payload when one literal information or one of multiple literal informations matches, otherwise throws a HasNotInformationError.
Interactive example
Syntax
Classic signature
typescript
function unwrapByInformationOrThrow<
GenericInput extends unknown,
GenericInformation extends (
GenericInput extends Either
? ReturnType<typeof informationKind.getValue<GenericInput>>
: never
),
>(
input: GenericInput,
information: GenericInformation | GenericInformation[],
): Unwrap<
Extract<
GenericInput,
Kind<typeof informationKind.definition, GenericInformation>
>
>Curried signature
typescript
function unwrapByInformationOrThrow<
GenericInput extends unknown,
const GenericInformation extends (
GenericInput extends Either
? ReturnType<typeof informationKind.getValue<GenericInput>>
: never
),
>(
information: GenericInformation | GenericInformation[],
): (
input: GenericInput,
) => Unwrap<
Extract<
GenericInput,
Kind<typeof informationKind.definition, GenericInformation>
>
>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. Otherwise, the function throws E.HasNotInformationError.
See also
unwrapByInformation– Non-throwing variant that returns the input unchanged when there is no match.hasInformation– Non-throwing check on literal information.whenHasInformation– Callback-based variant.
