Implementing an interface into an Effect service involves defining the service in a way that alig...

How am I able to implement an interface into an Effect service?
I am following a layered folder structure approach, ensuring seperation of concerns for Infra, Application, Domain

Am I using Effect service correctly here? Basically the reason for using it is to create a Repository layer to handle User persistence.
Sidenote: I am coming from using plain TS for dependency injection.

I know this code is wrong since there is no autocomplete inside the Effect generator & I am clearly doing something wrong.

// Exists in application layer (application/ports/user.ts)
interface IUserRepository {
  save: (event: UserCreated): Effect.Effect<never, Error, void>;
}

// Exists in infrastructure layer (infrastructure/persistence/userRepository.ts)
export class UserRepository extends Effect.Service<IUserRepository>()("UserRepository", {
  effect: Effect.gen(function* () {
    return {
        // impl here
        save() {}
    } as IUserRepository;
  },
  // Include when I need them
  // dependencies: [
  // ],
}) {

// Update 1:

export class UserRepository extends Effect.Service<IUserRepository>()("UserRepository", {
  effect: Effect.gen(function* () {
    return {
        // impl here
        save() {}
    } as IUserRepository; <~ I could add this? Just curious if there is a better practise

  },
Was this page helpful?