Effect CommunityEC
Effect Community15mo ago
24 replies
Jambudipa

Type problem with BunRuntime and HttpRouter

Should I expect the HttpLive to have this type?

// HttpLive.HttpLive<never, never, Scope | Language>
const HttpLive = HttpRouter.empty.pipe(
  HttpRouter.post('/rpc', toHttpApp(appRouter)),
  HttpServer.serve(HttpMiddleware.cors({
    allowedHeaders: ['*'],
    allowedMethods: ['*'],
  })),
  HttpServer.withLogAddress,
  Layer.provide(BunHttpServer.layer({ port: 3000 })),
  Layer.provide(MainLive)
);

BunRuntime.runMain(Layer.launch(HttpLive));


I don't think the type of my appRouter is right:
// RpcRouter<Search, SearchService>
export const appRouter = RpcRouter.make(
  Rpc.effect(Search, (request) => SearchService.pipe(
    Effect.andThen((search) => search.search('Hello'))
  ))
);

export type AppRouter = typeof appRouter;

...but I can't find a good example anywhere.

I believe I may be providing my services badly?
export const MainLive = Layer.mergeAll(SearchServiceLive, LanguageLive);

...which is part of HttpLive above.

The fact is, the code runs. I just get a type warning on BunRuntime.runMain():
Argument of type Effect<never, never, Language | Scope> is not assignable to parameter of type Effect<never, never, never>

Type Language | Scope is not assignable to type never

Type Language is not assignable to type never
Was this page helpful?