Trouble with TypeScript Types in Effect Wrapper Function

i'm trying to extract a wrapper function that takes a generator and context. however, i'm finding it impossible to get the types right.
export async function loader({ context }: Route.LoaderArgs) {
  const program = Effect.gen(function* () {
    const service = yield* GreeterService;
    const output = yield* service.sayHello({ name: "Dave" });
    yield* Effect.log(`message received: ${output.message}`);
    return { message: output.message };
  });
  return Effect.runPromise(Effect.provide(program, context.serviceContext));
}


i'd like to have a wrapper function that looks like:
export function makeEffectLoader<R, E, A>(
  generator: (
    context: Route.LoaderArgs
  ) => Generator<Effect.Effect<R, E, A>, A, unknown>
): (context: Route.LoaderArgs) => Promise<A> {
  return async (context: Route.LoaderArgs): Promise<A> => {
    // ****
    // Type 'Effect<R, E, A>' is missing the following properties from type 'YieldWrap<Effect<any, any, any>>': #private, [YieldWrapTypeId]
    const program: Effect.Effect<A, Error, ServiceContext> = Effect.gen(() =>
      generator(context)
    );
    // (alias) type ServiceContext = Context<GreeterService | GreeterClient>
    return Effect.runPromise(
      // ts: Argument of type 'Effect<A, Error, Context<GreeterService | GreeterClient>>' is not assignable to parameter of type 'Effect<A, Error, never>'.
      // Type 'Context<GreeterService | GreeterClient>' is not assignable to type 'never'.
      Effect.provide(program, context.context.serviceContext)
    );
  };
}


but effect doesn't seem to play nicely with typing. any help?
Was this page helpful?