TypeScript's type system can sometimes be tricky when dealing with higher-order functions like `E...

Is Effect.retry() not typed completely?

My first try was this:
const retryUsingMyPolicy: <A, R>(self: Effect.Effect<A, unknown, R>) => Effect.Effect<A, unknown, R>
// the types are not in my code!
// I am using them here just to show you what I get on hover from the LSP.
// I can't actually use this because it makes any errors from effects I pipe into this,
// to also become `unknown`.

Cause I wanted to reuse the effect that it returns, to reduce GCs, but it "swallows" (hides?) the E (error) generic type... So I tried to add the types myself:
export const retryUsingMyPolicy: <A, E, R>() => Effect.Effect<
  A,
  E,
  R
> = Effect.retry(myPolicy);

That is what I am trying to write, but the error is:
ts: Type '<A, R>(self: Effect<A, E, R>) => Effect<A, E, R>' is not assignable to type '<A, E, R>() => Effect<A, E, R>'.
  Target signature provides too few arguments. Expected 1 or more, but got 0. [2322]

If I understand correctly, retry is generically typed as <A, R>, there is no error there.

This means I cannot use the above code. I have to inline Effect.retry(myPolicy) everywhere I need to retry effects using the same policy, e.g. return pipe(myEffect, Effect.retry(myPolicy)).
Was this page helpful?