Search code examples
angularrxjsngrxngrx-effectsngrx-store

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}
          ))
    });

above code gives me Argument of type '(payload: any) => void' is not assignable to parameter of type '(value: any, index: number) => ObservableInput'. Type 'void' is not assignable to type 'ObservableInput'. where could be the mistake be. I have followed the ngrx effects official intro at https://github.com/ngrx/effects/blob/master/docs/intro.md .


Solution

  • The problem is that your switchMap should return a value; its returning void as you have it.

    Try this

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