调用效果器上的Web服务时我遇到打字问题
我在这里创建了效果
$LoadSchedulingsByMission = createEffect(() =>
this.actions$.pipe(
ofType<any>(ESchedulesActions.GetSchedulesByDirection),
mergeMap(action =>
this.apiCallsService.getDirections(action.payload, '2016-04-18').pipe(
map(trips => ({ type: ESchedulesActions.GetSchedulesByDirectionSuccess, payload: trips })),
catchError(() => EMPTY)
)
)
)
);
GetSchedulesByDirection
操作
export class GetDirections implements Action {
public readonly type = ESchedulesActions.GetSchedulesByDirection;
constructor(public payload: string[]) {}
}
然后我致电http服务
getDirections(data: string[], date:string) {
const groupByDirection:any={};
data.map(elm=> {
let dirUrl=`.....date=${date}&directions=${elm}`
this.http.get<ISchedules>(dirUrl).pipe(map(dirData=>{
groupByDirection[elm].push(dirData.data)
}))
})
return groupByDirection as ISchedules;
}
最后Success
动作
export class GetDirectionsSuccess implements Action {
public readonly type = ESchedulesActions.GetSchedulesByDirectionSuccess;
constructor(public payload: ISchedules) {}
}
减速器
case ESchedulesActions.GetSchedulesByDirection: {
return {
...state,
};
}
case ESchedulesActions.GetSchedulesByDirectionSuccess: {
return {
...state,
directions: action.payload
};
}
我收到此错误
类型'Observable'不可分配给类型 '可观察的| ((... args:any [])=>可观察)'。
类型“可观察”不能分配给类型 “可观察”。 类型“ {}”中缺少属性“类型”,但类型为“操作”中则为必需。
更新
我注意到getDirection
服务函数正在返回对象,但是在其他相同的行为效果中,服务正在返回对象的Observable。
因此我将服务修改为,错误消失了。
getDirections(data: string[], date:string) {
const groupByDirection:any={};
data.map(elm=> {
let dirUrl=`...date=${date}&directions=${elm}`
this.http.get<ISchedules>(dirUrl).pipe(map(dirData=>{
groupByDirection[elm].push(dirData.data)
}))
})
return of(groupByDirection);
这是正确的解决方案吗?