繁体   English   中英

ngrx 效果导致类型“void”不可分配给类型“ObservableInput”

[英]ngrx effects gives Type 'void' is not assignable to type 'ObservableInput'

@Injectable()
export class ApiSearchEffects {

  @Effect()
  search$: Observable<any>
    = this.actions$
    .ofType(query.ActionTypes.QUERYSERVER)
    .debounceTime(300)
    .map((action: query.QueryServerAction) => action.payload)
    .switchMap(payload => {
      console.log(payload);
      const nextSearch$ = this.actions$.ofType(query.ActionTypes.QUERYSERVER).skip(1);

      this.searchService.getsearchresults(payload)
        .takeUntil(nextSearch$)
        .map((response) =>
          ({type: '[Search] Change', payload: response}
          ))
    });

上面的代码给了我 '(payload: any) => void' 类型的参数不能分配给类型 '(value: any, index: number) => ObservableInput' 的参数。 “void”类型不能分配给“ObservableInput”类型。 哪里可能出错。 我遵循了https://github.com/ngrx/effects/blob/master/docs/intro.md 上的 ngrx 效果官方介绍。

问题是你的 switchMap 应该返回一个值; 当你拥有它时,它会返回无效。

尝试这个

  return this.searchService.getsearchresults(payload)
        .takeUntil(nextSearch$)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM