Refactoring Error: Using Effect.map Instead of Effect.flatMap in TypeScript

I found myself making a very silly error recently while refactoring. I started with an Effect.Effect<void, never, never> and the refactor was because I needed to do some effectful computation before that. No worries, I'll use the Effect.map combinator so it looks like this:

const refactored: Effect.Effect<void> = Effect.map(Effect.succeed(1), Console.log);


Where Effect.succeed is the effectful computation/dependency that I added and Console.log is the old Effect of type Effect.Effect<void, never, never>.

The problem? I used Effect.map and not Effect.flatMap 🤦 and even though I have explicitly typed this it still type checked just find. Turns out Effect.Effect<Effect.Effect<void>> is assignable to Effect.Effect<void> (and I don't think that can be changed?).

I've included a concise snippet of the code I was refactoring in a comment, as the examples above don't feel too realistic. Nonetheless, this feels like a skill issue of me forgetting to use flatMap instead of Map. I'm wondering if there are any other Effect combinators that could have prevented me from making this error?
Was this page helpful?