Effect CommunityEC
Effect Community•2y ago•
48 replies
Toby

Troubleshooting TypeScript Code for Combining Types with Effect Library

Can someone spot where I'm going wrong here:

import { Effect as E, Context, Layer, pipe } from "effect"

type A = { a: string }
type AB = A & { b: string }
type ABC = AB & { c: string }

const A = Context.GenericTag<A>('@services/A')
const AB = Context.GenericTag<AB>('@services/AB')
const ABC = Context.GenericTag<ABC>('@services/ABC')

const layerA: Layer.Layer<A> = Layer.succeed(A, { a: "a" })

// requires AB
const effectABC: E.Effect<ABC, never, AB> = pipe(AB, E.map(({ a, b }) => ({ a, b, c: "c" })))
// provide A, not AB yet all requirements are met?
const effectABC_noRequirements: E.Effect<ABC, never, never> = pipe(effectABC, E.provide(layerA))

// Blows up with Error: Service not found: @services/AB
E.runSync(effectABC_noRequirements)


I can't see how I can go from E.Effect<ABC, never, AB> to E.Effect<ABC, never, never> by providing A (not AB) 🤔
Was this page helpful?