NgRX effects - Type 'Observable' is not assignable to type 'Observable'

前端 未结 9 1097
你的背包
你的背包 2020-12-16 10:12

While working with NgRX 8 my colleagues and me are frequently facing a weird error message when implementing the effects.

Type \'Observable

9条回答
  •  执念已碎
    2020-12-16 10:26

    In case of dealing with this problem and using official ngrx 8 example.

    loadMovies$ = createEffect(() => this.actions$.pipe(
        ofType('[Movies Page] Load Movies'),
        mergeMap(() => this.moviesService.getAll()
          .pipe(
            map(movies => ({ type: '[Movies API] Movies Loaded Success', payload: movies })),
            catchError(() => EMPTY)
          ))
       )
    );
    

    Easy and fast solution can be putting "any" type.

    loadMovies$: any = createEffect((): any => this.actions$.pipe(
        ofType('[Movies Page] Load Movies'),
        mergeMap(() => this.moviesService.getAll()
          .pipe(
            map(movies => ({ type: '[Movies API] Movies Loaded Success', payload: movies })),
            catchError(() => EMPTY)
          ))
       )
    );
    

    Do not forget imports for rxjs operators, observables.

    In case of dealing with action payload - props, define an action type.

    ofType
    

    or

    ofType>
    

提交回复
热议问题