Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rxjs error with pipe of operators

Tags:

angular

rxjs

I have an error in switchMap operator:

@Injectable()
export class AvailableStoreTypesLoadedEffect {
constructor(private actions$: Actions,
          private service: AvailableService) {

}

 @Effect()
 AvailableStoreTypesLoadedEffect$ = this.actions$
 .ofType(FETCH_AVAILABLE_STORE_TYPES)
 .pipe(
   switchMap(action => this.service.fetchAvailableStoreTypes()),//Error:(22, 9) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.
   map(res => new AvailableStoreTypesLoaded(res))
  );
}

I tried with:

Observable.of({})
  .pipe(
    switchMap(() => Observable.of({}))//Error:(22, 9) TS2684:The 'this' context of type 'void' is not assignable to method's 'this' of type 'Observable<{}>'.
  );

but I get the same error.

My environment is:

  • angular 5.0.3
  • typescript 2.4.2
  • rxjs 5.5.2
like image 937
yamidvo Avatar asked Feb 02 '26 03:02

yamidvo


1 Answers

I imported the library from import { mergeMap } from 'rxjs/operator/mergeMap'; but it must be imported from import { mergeMap } from 'rxjs/operators';

like image 63
yamidvo Avatar answered Feb 03 '26 16:02

yamidvo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!