首页 > 解决方案 > 类型'可观察的' 不可分配给类型 'EffectResult'

问题描述

完整代码取自documentaion:

import { Injectable } from "@angular/core";
import { Actions, createEffect, ofType } from "@ngrx/effects";
import { of } from "rxjs";
import { map, mergeMap, catchError } from "rxjs/operators";

@Injectable()
export class RegistryEffects {
  loadMovies$ = createEffect(() =>
    this.actions$.pipe(
      ofType("load"),
      mergeMap(() =>
        this.moviesService.getAll().pipe(
          map((movies) => ({
            type: "loaded_success",
            payload: movies,
          })),
          catchError(() => of({ type: "loaded_error" }))
        )
      )
    )
  );

  constructor(private actions$: Actions, private moviesService: any) {}
}

我收到此错误消息:

类型“Observable”不可分配给类型“EffectResult”。类型“Observable”不可分配给类型“Observable”。'{}' 类型中缺少属性 'type',但在 'Action'.ts(2322) 类型中需要属性'type':此处声明了'type'。effect_creator.d.ts(42, 161):预期类型来自此签名的返回类型。

如何修复它,我的 Redux 出了什么问题?

链接到官方示例

标签: angularreduxredux-observable

解决方案


推荐阅读