Type Error in Reusable Error Handling Function for Multiple Tagged Errors in Effect 3.7 and Schem...

I'm trying to create a reusable error handling function wrapping catchTags, similar to what's been discussed effect-beginners-🚀 however I'm getting a type error when trying to handle more than one tagged error. I wonder if it's a regression since from what I gather something like this worked for the author of the linked thread. I'm on effect 3.7 and schema 0.72.

import { Schema } from '@effect/schema'
import { Effect } from 'effect'
import { unify } from 'effect/Unify'

export class ErrorA extends Schema.TaggedError<ErrorA>()(
  'ErrorA',
  {},
) {}

export class ErrorB extends Schema.TaggedError<ErrorB>()(
  'ErrorB',
  {},
) {}

const program = Effect.suspend(unify(() =>
  Math.random() > 0.5
    ? Effect.fail(new ErrorA())
    : Effect.fail(new ErrorB())
))

export const handledOk = program.pipe(
  Effect.catchTags({
    ErrorA: Effect.die,
    ErrorB: error => Effect.succeed(error._tag),
  }),
)

export const handleKnownErrors = <A, E, R>(
  effect: Effect.Effect<A, E | ErrorA | ErrorB, R>,
) =>
  // Type error here
  Effect.catchTags(effect, {
    ErrorA: Effect.die,
    ErrorB: error => Effect.succeed(error._tag),
  })

// single error works
export const singleErrorOk = <A, E, R>(
  effect: Effect.Effect<A, E | ErrorA, R>,
) =>
  Effect.catchTags(effect, {
    ErrorA: Effect.die,
  })


the same in playground
Was this page helpful?