I'm encountering an issue while working with ngrx. I keep receiving an error when attempting to implement a simple effect. The specific error message mentions that the Argument of type '
MonoTypeOperatorFunction<LoadContainerAction>
' is not compatible with the parameter of type 'OperatorFunction<Action, Action>
' in relation to the startWith method.
@Injectable()
export class Effects {
@Effect()
loadCollection$: Observable<Action> = this.actions$
.pipe(
ofType(ActionTypes.LOAD_CONTAINER),
startWith(new LoadContainerAction()),
switchMap(() =>
this.apiService.get<Container[]>("books")
.then(items => new LoadContainerSuccessAction(items))
.catch(error => of(new LoadContainerFailAction(error)))
)
);
constructor(private actions$: Actions, private apiService: ApiService) { }
}
This is how ActionTypes and LoadContainerAction are defined:
export enum ActionTypes {
LOAD_CONTAINER = "[container] load",
LOAD_CONTAINER_SUCCESS = "[container] load success",
LOAD_CONTAINER_FAILURE = "[container] load fail",
}
export class LoadContainerAction implements Action {
readonly type = ActionTypes.LOAD_CONTAINER;
}
These are the relevant imports being used:
import { Injectable } from "@angular/core";
import { Action } from "@ngrx/store";
import { Effect, Actions, ofType } from "@ngrx/effects";
import { Observable, of } from "rxjs";
import { startWith, switchMap } from "rxjs/operators";
The versions of rxjs and ngrx being utilized are 6.1.0 and 6.0.0-beta.1 respectively.