Effect CommunityEC
Effect Community3y ago
6 replies
Boi

Trouble with Simple Service Example

Hello, I am having trouble getting the simple service example of the doc working without error.
import { pipe } from '@effect/data/Function'
import * as Effect from "@effect/io/Effect"
import * as Context from "@effect/data/Context"

interface Random {
  readonly next: () => Effect.Effect<never, never, number>
}

const Random = Context.Tag<Random>()

const program = pipe(
  Random,
  Effect.flatMap((random) => random.next()),
  Effect.flatMap((randomNumber) => Effect.logInfo(`${randomNumber}`))
)

Piping the Random Tag into Effect.flatMap gives me the following error
1. Argument of type '<R, E>(self: Effect<R, E, Random>) => Effect<R, E, number>' is not assignable to parameter of type '(a: Tag<Random, Random>) => Effect<Random, never, number>'.
     Types of parameters 'self' and 'a' are incompatible.


Using Effect.serviceOption instead works, but it removes the Tag from the Effect signature. All @effect packages are at the latest, as well as Typescript. Any idea on what might be causing this? Also worth mentioning that I've been using effect-ts for a week now and everything else works as expected so far except this.
Was this page helpful?