How to Handle a Specific Error Type in a Generic Error Type with Effect Typescript Library

Is there a way for me to express the following. I'm trying to do type-level stuff to operate on a single specific error within a generic wider error type. (It's difficult because i can express that a generic type extends a union, but i can't express that a generic type contains a union member. This might not be the issue here though)

https://effect.website/play/#8e329ab7064e

export class MyError extends Data.TaggedError('MyError')<{
  message: string
}> {}

export class OtherError extends Data.TaggedError('OtherError')<{
  message: string
}> {}

const catchMyError =
  <A, E>(
    eff: Effect.Effect<
      A,
      MyError | OtherError | E
    >,
  ): Effect.Effect<A, OtherError | E> =>
    eff.pipe(
      Effect.catchTags({
        MyError: (e) => {
          return new OtherError({ message: e.message })
        },
      }),
    )
Was this page helpful?