Issue with `Match.when` Type Inference and Handling `void` Type in Effect Typescript

Has something happened with the Match.when api such that passing a typeguard doesn't infer
x
correctly? given a generic handler, all i want to do is lift the Redirect out of the error channel (or left channel), handle it internally, then propogate the remaining errors to the consumer. This seems to work just fine, but
x
current as an inferred value of Match.Types.WhenMatch<E, (u: unknown, overrideOptions?: ParseOptions | number) => u is Redirect>.

bonus points if someone can figure out a way to remove the void type left by the callback that still propogates to the error/left channel...i don't think thats even possible if it isn't being thrown...

  function handler<A, E>(effect: Effect.Effect<A, E, RuntimeDependencies>) {
    return pipe(effect, Effect.either, SdkRuntime.runPromise).then(
      Either.mapLeft((left) => {
        const matchError = Match.value(left).pipe(
          Match.when(Schema.is(Redirect), (x) => opts.onSessionExpired((x as Redirect).to)), // forced to cast??
          Match.orElse((err) => err),
        );
        return matchError;
      }),
    );
  }


the playground with a full example here https://effect.website/play/#719c294279e7
Was this page helpful?