Applying Conditional Schedule in Effect Pipe Using Effect.if

In the same way, I would like to apply a conditional schedule
myEffectFunction().pipe(
  Effect.tap(() => anotherFunction()),
  Effect.retry(Schedule.spaced(Duration.seconds(5))),
  Effect.repeat(Schedule.spaced(Duration.weeks(1))), // <<-- I would like this Schedule to be applied only when flag === true
)


I tried
const flag = true;

myEffectFunction().pipe(
  Effect.tap(() => anotherFunction()),
  Effect.retry(Schedule.spaced(Duration.seconds(5))),
  Effect.if(flag, {
    onTrue: () => Effect.repeat(Schedule.spaced(Duration.weeks(1))),
  }),
)

but this gives me typescript errors is not assignable to type Effect<unknown, unknown, unknown> and feels like this might not be the right way to do it?
Was this page helpful?