Issue with Type Inference in Effect.Service with Generic Keys

i have this type that provides access to data based on model provider and then id, for example map["openai"]['gpt-4o"]
type ModelMap<T> = {
  [K in ModelProviders]: Record<
    Extract<ModelIdentifier, { provider: K }>["id"],
    T
  >;
};

declare const map: ModelMap<number>;


the generic type key inference works with a regular function
const fn = <P extends keyof typeof map, I extends keyof (typeof map)[P]>(
  provider: P,
  id: I,
) => map[provider][id];

const x = fn("anthropic", "claude-3-5-sonnet-latest"); // resolves to x: number



but when using
Effect.Service
, I resolves to never
class AiModel extends Effect.Service<AiModel>()("@4nswer/AiModel", {
  accessors: true,
  effect: <P extends keyof typeof map, I extends keyof (typeof map)[P]>(
    provider: P,
    id: I,
  ) => Effect.succeed({ x: provider, y: id }),
}) {}


// this is the resolved type of the AiModel interface:
(property) {
    x: "openai" | "anthropic";
    y: never;
}


why doesn't this work?
Was this page helpful?