我在switchMap运算符中有错误:
@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))
);
}
我尝试过:
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<{}>'.
);
但我得到了同样的错误 .
我的环境是:
-
角5.0.3
-
打字稿2.4.2
-
rxjs 5.5.2
1 回答
我从
import { mergeMap } from 'rxjs/operator/mergeMap';
导入了库,但必须从import { mergeMap } from 'rxjs/operators';
导入