ngrx-effects将类型错误视为无法分配

问题描述 投票:0回答:1

这是我的特效文件,

import { Injectable } from "@angular/core";
import { Action } from "@ngrx/store";
import { Actions, Effect, ofType } from "@ngrx/effects";
import { Observable, of } from "rxjs";
import { map, mergeMap, switchMap, catchError } from "rxjs/operators";
import { ModelCourse } from "./../models";
import { CourseService } from "./../services/course.service";
import { 
            courseActionTypes, 
            LoadCourse, 
            LoadCourseSuccess, 
            LoadCourseFail, 
            UpdateCourse,
            UpdateCourseSuccess,
            UpdateCourseFail } from "./course.actions";

@Injectable() 
export class CourseEffects {

    constructor(private courseService:CourseService, private actions:Actions){}

    @Effect()
        LoadCourse = this.actions.pipe( 
            ofType(LoadCourse.TYPE),
            mergeMap((action:LoadCourse) => this.courseService.getCourse().pipe(
                map((courses:ModelCourse[]) => {
                    return new LoadCourseSuccess(courses);
                }),
                catchError(err => of(new LoadCourseFail(err)))
            ))

        )

    @Effect()
        UpdateCourse = this.actions.pipe(
            ofType(UpdateCourse.TYPE),
            map((action:UpdateCourse) => action.payload),
            mergeMap((course:ModelCourse) => 
                this.courseService.updateCourse(course).pipe(
                    map((course) => (new UpdateCourseSuccess(course))),
                    catchError(err => (new UpdateCourseFail(err)))
                )
            )
        )

}

从上面,我收到以下错误。有人帮我吗?

ERROR in src/app/setup-config/state/course.effects.ts(41,24): error TS2322: Type 'UpdateCourseFail' is not assignable to type 'ObservableInput<{}>'.
  Property '[Symbol.iterator]' is missing in type 'UpdateCourseFail' but required in type 'Iterable<{}>'.
angular7 ngrx-effects
1个回答
0
投票

这是我的错字,我用of运算符更新了catchError。它现在工作正常。

这是更新的代码:

 catchError(err => of(new UpdateCourseFail(err)))

谢谢!!

© www.soinside.com 2019 - 2024. All rights reserved.