TypeScript Error When Using `HttpApi.addHttpApi` for API Versioning with Effect

I'm trying out Effect for the first time, I'm trying to build a http server using the HTTP API from @effect/platform. I'm trying to create api groups to handle api versioning and I found out that we can't put a group inside another one and after digging through the source code for a few I discovered HttpApi.addHttpApi. I managed to write something like this:

export const Api = HttpApi.make('api').addHttpApi(V1Api).addHttpApi(V2Api);

export const ApiLive = Layer.provide(HttpApiBuilder.api(Api), [
  HttpHealthLive,
  HttpHealthLiveV2,
]);


It works fine, but I get a TS error on my run command:

const HttpLive = HttpApiBuilder.serve(HttpMiddleware.logger).pipe(
  Layer.provide(HttpApiSwagger.layer()),
  Layer.provide(ApiLive),
  HttpServer.withLogAddress,
  Layer.provide(NodeHttpServer.layer(createServer, { port: 3000 })),
);

/**
 * The 'this' context of type 'Effect<never, ServeError, ApiGroup<"api", "healthv1"> | ApiGroup<"api", "healthv2">>'
 * is not assignable to method's 'this' of type 'Effect<unknown, unknown, never>'.
 * Type 'ApiGroup<"api", "healthv1"> | ApiGroup<"api", "healthv2">' is not assignable to type 'never'.
 * Type 'ApiGroup<"api", "healthv1">' is not assignable to type 'never'.ts(2684)
 */
Layer.launch(HttpLive).pipe(NodeRuntime.runMain);


I'm open to suggestions too, I'm pretty sure I'm doing everything wrong, but it's part of learning haha
Was this page helpful?