Type Error with `Effect.catchSome` After Updating `effect` Library

Hi! While updating effect from from 2.14.13 to 3.0, I got a type error on Effect.catchSome.

It seems that if you try to pattern match err: NoInfer<Error | CustomError> it breaks, with both typescript 5.4.3 and 5.4.5.

Here I was using ts-pattern, but the same error occurs with effect/Match

import * as Effect from "effect/Effect"
import * as F from "effect/Function"
import * as Option from "effect/Option"
import { match } from "ts-pattern"
import * as Match from "effect/Match"

type CustomError = {
    readonly _tag: "CustomError"
    readonly message: string
}

declare const doSomething: Effect.Effect<void, Error | CustomError>

// with ts-pattern
F.pipe(
    doSomething,
    Effect.catchSome((err) => {
        return (
            match(err)
                .with({ _tag: "CustomError" }, (e) => Option.some(Effect.logWarning(e.message)))
                //      ^TS2353: Object literal may only specify known properties, and _tag does not exist in type...
                .otherwise(() => Option.none())
        )
    }),
)

// with effect/Match
F.pipe(
    doSomething,
    Effect.catchSome((err) => {
        return F.pipe(
            Match.value(err),
            Match.when({ _tag: "CustomError" }, (e) => Option.some(Effect.logWarning(e.message))),
            //           ^TS2353: Object literal may only specify known properties, and _tag does not exist in type...
            Match.orElse(() => Option.none()),
        )
    }),
)


I now that I could rewrite this code with Effect.catchTag("CustomError", ...) and all good again, but it just feels like a weird error to me.

Another way to solve this is by putting an explicit input type to match function like Match.value<Error | CustomError>(err)
Was this page helpful?