switchMap与角6+ NGRX效果抛出一个类型错误

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

我在角6 + NGRX应用程序写入的影响,但它引发以下错误。

类型Observable<RouteSuccessAction>的说法是不能分配给类型<value: never, index: number> => ObservableInput<Action>的参数

以下是代码片段。

route.effects.ts

@Injectable()
export class RouteEffect {
    constructor(private actions: Actions, private routeService: RouteService) {
    }

    @Effect()
    getRoutes$: Observable<Action> = this.actions.pipe(
        ofType(RouteActions.RouteActionTypes.ROUTE_LOAD), switchMap(
            this.routeService.getRoutes().pipe(
                map(routes => new RouteActions.RouteSuccessAction(routes.route))
            )
        )
    );
}

route.actions.ts

import { Action } from '@ngrx/store';
import { Route } from '../model';
export enum RouteActionTypes {
    GET_ROUTE = '[GET ROUTE] GET',
    ROUTE_FAIL = '[ROUTE_FAIL] FAIL',
    ROUTE_SUCCESS = '[ROUTE_SUCCESS] SUCCESS',
    ROUTE_LOAD = '[ROUTE_LOAD] LOAD',

}

export class GetRouteAction implements Action {
    readonly type = RouteActionTypes.GET_ROUTE;

}
export class RouteSuccessAction implements Action {
    readonly type = RouteActionTypes.ROUTE_SUCCESS;
    constructor(public payload: Route[]) {
    }

}
export class RouteFailureAction implements Action {
    readonly type = RouteActionTypes.ROUTE_FAIL;
    constructor(public payload: any) {
    }

}
export type RouteActions = GetRouteAction | RouteSuccessAction | RouteFailureAction;

route.model.ts

export interface Route {
  'referringURL': string;
  'routeName': string;
  'visible': boolean;
}

服务返回以下响应

    [
        {
            "referringURL": "",
            "routeName": "route1",
            "visible": true
        },
        {
            "referringURL": "",
            "routeName": "route2",
            "visible": true
        },
        {
            "referringURL": "",
            "routeName": "route3",
            "visible": true
        }
]
angular6 ngrx
1个回答
4
投票

您switchmap是不是应该是一个函数

switchMap(() => ...)
© www.soinside.com 2019 - 2024. All rights reserved.