Effect CommunityEC
Effect Community2mo ago
6 replies
danielo515

Typing the Return Type of a Service Effect in TypeScript

How can I properly type the return type of the effect of a service?
I tried with the following, but instead of the breader type (LanguageModel) it is inferring the specific one returned from the function (which is one of the possible enum values):
export class AiModel extends Effect.Service<AiModel>()("AiModel", {
  effect: Effect.gen(function* () {
    const config = yield* AiConfig;
    const model: LanguageModel = createAzure({
      apiKey: config.apiKey,
      resourceName: config.resourceName,
    })("gpt-5-mini");
    return { model };
  }),
}) {
  static TestLayer = Layer.succeed(
    AiModel,
    AiModel.of({
      model: "test-model",
    }),
  );
}
Was this page helpful?