Skip to content

Commit f569a06

Browse files
committed
fix(types): tighten catchIf typing for HttpError values
1 parent c58f917 commit f569a06

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

packages/app/src/shell/api-client/create-client.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,26 @@ const createMethodHandlerWithUniversalDispatcher = (
353353
options
354354
)
355355

356-
const isHttpErrorValue = (error: unknown): error is { readonly _tag: "HttpError" } =>
356+
type HttpErrorTag = { readonly _tag: "HttpError" }
357+
358+
const isHttpErrorValue = (error: unknown): error is HttpErrorTag =>
357359
typeof error === "object"
358360
&& error !== null
359361
&& "_tag" in error
360362
&& Reflect.get(error, "_tag") === "HttpError"
361363

362364
const exposeHttpErrorsAsValues = <A, E>(
363365
request: Effect.Effect<A, E, HttpClient.HttpClient>
364-
): Effect.Effect<A | { readonly _tag: "HttpError" }, E, HttpClient.HttpClient> =>
366+
): Effect.Effect<
367+
A | Extract<E, HttpErrorTag>,
368+
Exclude<E, Extract<E, HttpErrorTag>>,
369+
HttpClient.HttpClient
370+
> =>
365371
request.pipe(
366-
Effect.catchIf(isHttpErrorValue, (error) => Effect.succeed(error))
372+
Effect.catchIf(
373+
(error): error is Extract<E, HttpErrorTag> => isHttpErrorValue(error),
374+
(error) => Effect.succeed(error)
375+
)
367376
)
368377

369378
const createMethodHandlerWithUniversalDispatcherValue = (

0 commit comments

Comments
 (0)