Mel Pacheco
Mel Pacheco

Reputation: 789

NGRX/store sideEffect issue with startWith

I have a side-effect that looks like this:

@Effect()
loadAll$: Observable<Action> = this.actions$
  .ofType(reservationsActions.LOAD_ALL)
  .startWith(new reservationsActions.LoadAll())
  .switchMap(() =>
    this.reservationsService.index() 
   .map((reservations: Reservation[]) => new reservationsActions.LoadAllSuccess(reservations))
);

I grabbed that from this repo ngrx example

and I get the following error:

Property 'startWith' does not exist on type 'Actions'.

Upvotes: 1

Views: 1038

Answers (2)

Eric S
Eric S

Reputation: 157

When upgrading to rxjs 6 you need to adjust your syntax to use the pipe operator.

Original

  @Effect()
  loadAll$: Observable<Action> = this.actions$
   .ofType(reservationsActions.LOAD_ALL)
   .startWith(new reservationsActions.LoadAll())
   .switchMap(() =>
     this.reservationsService.index() 
    .map((reservations: Reservation[]) => new 
         reservationsActions.LoadAllSuccess(reservations))
   );

New

  @Effect()
  loadAll$: Observable<Action> = this.actions$.pipe(
   ofType(reservationsActions.LOAD_ALL),
   startWith(new reservationsActions.LoadAll()),
  switchMap(() =>
    this.reservationsService.index() 
   .map((reservations: Reservation[]) => new 
reservationsActions.LoadAllSuccess(reservations))
   ));

Upvotes: 3

Mel Pacheco
Mel Pacheco

Reputation: 789

just figured it out, this was missing.

import 'rxjs/add/operator/startWith'

Upvotes: 0

Related Questions