Constraining a Generic for Match.valueTags in TypeScript

i dont' suppose there's a way to constrain a generic enough to be passed to a Match.valueTags? Im trying to create a watch wrapper (vue/nuxt) as a convenience for an interal sdk im developing. all errors are tagged errors. My issue is the L generic, not entirely sure how to wrangle the constraints enough to get this thing to behave....

import { Either, Match, Option, pipe } from "effect";
import { constVoid } from "effect/Function";
import { watch, type WatchOptions } from "vue";
import type { WatchResultArgs } from "./watch-result.types";

export function watchResult<L, R>(
  data: Ref<Either.Either<R, L> | undefined>,
  args: WatchResultArgs<L, R>,
  opts?: WatchOptions,
) {
  return watch(
    data,
    (value) => {
      return pipe(
        value,
        Option.fromNullable,
        Option.map(
          Either.match({
            onLeft: (error) => Match.valueTags(error)(args.onError), // Issue here
            onRight: (value) => args.onSuccess(value),
          }),
        ),
        Option.getOrElse(constVoid),
      );
    },
    opts,
  );
}


the api im aiming for looks like this

watchResult(data, {
  onSuccess: (value) => console.log(value),
  onError: {
    NotFoundError: (err) => redirect(err),
    UnexpectedError: (err) => redirect(err)
  }
})
Was this page helpful?