Assembling Functions Returning Effects into a Layer

SOLVED!

Hello, trying to assemble several functions that return an effect into a layer. For some reason TS says that deps are required for an effect although they are pulled in by a layer.

Toy example:
type A = {
    a: () => Effect.Effect<never, never, string>
}

const A = Context.Tag<A>()

type B = {
    b: () => Effect.Effect<never, never, string>
}

const B = Context.Tag<B>()

type C = {
    bbbaaa: (input: string) => Effect.Effect<never, never, string>
}

const C = Context.Tag<C>()

const aaa = (input: string) =>
    Effect.gen(function* (_) {
        const a = yield* _(A)

        return input + (yield* _(a.a()))
    })

const bbbaaa = (input: string) =>
    Effect.gen(function* (_) {
        const b = yield* _(B)

        return input + (yield* _(b.b())) + (yield* _(aaa(input)))
    })

// error: A | B is not assignable to type never
const LayerC_1 = Layer.effect(
    C,
    Effect.gen(function* (_) {
        const a = yield* _(A)
        const b = yield* _(B)

        return {
            bbbaaa: (input: string) =>
                Effect.gen(function* (_) {
                    return yield* _(bbbaaa(input))
                }),
        }
    }),
)

// error: type unknown is not assignable to type never
const LayerC_2 = Layer.effect(
    C,
    Effect.gen(function* (_) {
        const a = yield* _(A)
        const b = yield* _(B)
        
        // this was the bug
        const context = Context.empty().add(A, a).add(B, b)

        return {
            bbbaaa: (input: string) =>
                Effect.gen(function* (_) {
                    return yield* _(Effect.provide(bbbaaa(input), context))
                }),
        }
    }),
)


My goal in this toy example is to just create a layer that can produce C
Was this page helpful?