Skip to content

Commit

Permalink
Support tacit usage of Effect.tapErrorTag and Effect.catchTag (#3516
Browse files Browse the repository at this point in the history
)

Co-authored-by: maksim.khramtsov <maksim.khramtsov@btsdigital.kz>
  • Loading branch information
KhraksMamtsov and maksim.khramtsov authored Sep 1, 2024
1 parent 19a7c96 commit f6a469c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-rice-push.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"effect": patch
---

support tacit usage for `Effect.tapErrorTag` and `Effect.catchTag`
14 changes: 10 additions & 4 deletions packages/effect/dtslint/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,10 @@ pipe(
Effect.tapErrorTag("TestError1", () => Effect.succeed(1))
)

// $ExpectType Effect<number, TestError1 | TestError2, never>
hole<Effect.Effect<number, TestError1 | TestError2>>()
.pipe(Effect.tapErrorTag("TestError1", Effect.log))

// -------------------------------------------------------------------------------------
// catchTag
// -------------------------------------------------------------------------------------
Expand Down Expand Up @@ -578,6 +582,10 @@ Effect.catchTag(hole<Effect.Effect<number, TestError1>>(), "TestError1", (
_e // $ExpectType TestError1
) => Effect.succeed(1))

// $ExpectType Effect<number | void, TestError2, never>
hole<Effect.Effect<number, TestError1 | TestError2>>()
.pipe(Effect.catchTag("TestError1", Effect.log))

// $ExpectType Effect<number, never, never>
pipe(
hole<Effect.Effect<number, TestError1>>(),
Expand All @@ -586,10 +594,8 @@ pipe(
) => Effect.succeed(1))
)

// $ExpectType Effect<number, TestError2, never>
Effect.catchTag(hole<Effect.Effect<number, TestError1 | TestError2>>(), "TestError1", (
_e // $ExpectType TestError1
) => Effect.succeed(1))
// $ExpectType Effect<number | TestError1, TestError2, never>
Effect.catchTag(hole<Effect.Effect<number, TestError1 | TestError2>>(), "TestError1", Effect.succeed)

// $ExpectType Effect<number, TestError2, never>
pipe(
Expand Down
4 changes: 2 additions & 2 deletions packages/effect/src/Effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1832,7 +1832,7 @@ export const catchSomeDefect: {
export const catchTag: {
<K extends E extends { _tag: string } ? E["_tag"] : never, E, A1, E1, R1>(
k: K,
f: (e: Extract<E, { _tag: K }>) => Effect<A1, E1, R1>
f: (e: NoInfer<Extract<E, { _tag: K }>>) => Effect<A1, E1, R1>
): <A, R>(self: Effect<A, E, R>) => Effect<A1 | A, E1 | Exclude<E, { _tag: K }>, R1 | R>
<A, E, R, K extends E extends { _tag: string } ? E["_tag"] : never, R1, E1, A1>(
self: Effect<A, E, R>,
Expand Down Expand Up @@ -4347,7 +4347,7 @@ export const tapError: {
export const tapErrorTag: {
<K extends E extends { _tag: string } ? E["_tag"] : never, E, A1, E1, R1>(
k: K,
f: (e: Extract<E, { _tag: K }>) => Effect<A1, E1, R1>
f: (e: NoInfer<Extract<E, { _tag: K }>>) => Effect<A1, E1, R1>
): <A, R>(self: Effect<A, E, R>) => Effect<A, E | E1, R1 | R>
<A, E, R, K extends E extends { _tag: string } ? E["_tag"] : never, A1, E1, R1>(
self: Effect<A, E, R>,
Expand Down

0 comments on commit f6a469c

Please sign in to comment.