Effect CommunityEC
Effect Community3y ago
5 replies
kayng84

Question about Do notation

Basically, I have some experiences with FP-TS and I playing around with Effect-TS, below is the code I playing with Do notation
const program = pipe(
  Effect.Do,
  // error next line
  Effect.bind('connIdToSocket', () => Ref.make(Map.empty<string, SocketStream>())), 
  Effect.bind('clientIdToConnId', () => Ref.make(Map.empty<string, string[]>())),
  Effect.flatMap(({connIdToSocket, clientIdToConnId}) => {
    // do something with connIdToSocket and clientIdToConnId
  })
)


But the typescript complaint
Argument of type '<R, E>(self: Effect<R, E, unknown>) => Effect<R, E, { connIdToSocket: Ref<MutableHashMap<string, SocketStream>>; }>' is not assignable to parameter of type '(a: (_: void) => Effect<never, never, {}>) => Effect<unknown, unknown, { connIdToSocket: Ref<MutableHashMap<string, SocketStream>>; }>'.
  Types of parameters 'self' and 'a' are incompatible.
    Type '(_: void) => Effect<never, never, {}>' is not assignable to type 'Effect<unknown, unknown, unknown>'.ts(2345)


I also not get any chance by wrap Ref.make with Effect.succeed

I even do the simplest thing in this context:
const program = pipe(
  Effect.Do,
  Effect.bind('connIdToSocket', () => Effect.succeed(1))
  // Effect.bind('clientIdToConnId', () => Ref.make(Map.empty<string, string[]>())),
  // Effect.flatMap(({connIdToSocket, clientIdToConnId}) => {
  //   // do something with connIdToSocket and clientIdToConnId
  // })
)

It still error
Argument of type '<R, E>(self: Effect<R, E, unknown>) => Effect<R, E, { connIdToSocket: number; }>' is not assignable to parameter of type '(a: (_: void) => Effect<never, never, {}>) => Effect<unknown, unknown, { connIdToSocket: number; }>'.
  Types of parameters 'self' and 'a' are incompatible.
    Type '(_: void) => Effect<never, never, {}>' is not assignable to type 'Effect<unknown, unknown, unknown>'.ts(2345)


Please help
Was this page helpful?