What values should switchMap return, not to get this error? TypeError: You provided 'undefined' where a stream was expected

Viewed 23
private initPipes() {
    if (![ImportStatus.SUCCESS, ImportStatus.FAILURE].includes(this.event?.status)) {
      interval(this.dataPollingIntervalSec * 1000)
        .pipe(
          takeWhile(() => this.alive && this.continuePolling),
          switchMap(() => {
            const observables = [
              this.importStatusService
                .getDetails(this.event.executionId)
                .pipe(tap((event) => (this.event = event))),
              this.selectActionObservable(this.event.status),
            ];

            return forkJoin(observables);
          }),
        )
        .subscribe(() => this.cd.detectChanges());
    }
  }

This part of code produces a typeError

I caught the Error and it seems that forkJoin(observables) is undefined and cannot be returned by switchMap but in debugger, it's not undefined but its an observable

1 Answers

Based on the details shared, you can solve it by setting type as Array<Observable<any>>

private initPipes() {
    if (![ImportStatus.SUCCESS, ImportStatus.FAILURE].includes(this.event?.status)) {
      interval(this.dataPollingIntervalSec * 1000)
        .pipe(
          takeWhile(() => this.alive && this.continuePolling),
          switchMap(() => {
            const observables: Array<Observable<any>> = [ // <-changed here!
              this.importStatusService
                .getDetails(this.event.executionId)
                .pipe(tap((event) => (this.event = event))),
              this.selectActionObservable(this.event.status),
            ];

            return forkJoin(observables);
          }),
        )
        .subscribe(() => this.cd.detectChanges());
    }
  }
Related