Effect CommunityEC
Effect Community7mo ago
12 replies
ryan

Issue with HttpClient Dependency Injection in Effect Typescript Library

I feel bad asking another question, but i'm running into a similar problem that I know is a me problem again, but clearly i'm not understanding something.

I am creating a server, I then provide the spec, the route handler, etc.

All thats fine.

I create this handler which has this type:

Layer.Layer<HttpApiGroup.ApiGroup<"ApiSpec", "AI">, never, AiService>


AIService needs HttpClient

Effect.Effect<{
    askLLM: (prompt: string, opts?: LlmRequestOptions) => Effect.Effect<{
        result: string;
    }, AiError, never>;
}, never, HttpClient.HttpClient>


The part thats throwing me off is the HttpClient. This is a handler, so i should have HttpClient there, however I have a service that uses the HttpClient, not directly in the handler.

So my spec where I launch my server has this issue:

The 'this' context of type 'Effect<never, ServeError, HttpClient>' is not assignable to method's 'this' of type 'Effect<unknown, unknown, never>'.
  Type 'HttpClient' is not assignable to type 'never'.(2684


So based on my conversation yesterday, i must be trying to use the HttpClient where I can't use it? Should I pass the
client
I yield* to the service?

Is this something special about Effect.service that i'm messing up?

Excuse the code Its not clean at all but i tried to remove noise that wasn't relative to the problem.


I have a play link https://effect.website/play#2730e05a7a56

I apologize again for another question i just have some mental block about this i'm not resolving. i've tried a few different things.

I can manually provide a NodeHttp layer but i'm not sure thats the right thing to do
Was this page helpful?