Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

349
Vistas
forkJoin return error You provided 'undefined' where a stream was expected

Previously, I asked an issue about return nested httprequest with wait subrequest.

https://stackoverflow.com/questions/69308614/angular-map-wait-observable-to-complete[Angular map wait Observable to complete]1

I made some changes to it, but it throw error

Error: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.

Here are my update code

      test2(): Observable<Student[]> {
    return this.test1().pipe(
      mergeMap((result) => {
        if (!result) {
          return of(result);
        }
        return forkJoin(
          result.map((rr) => {
            if (rr.age === 1) {
              rr.age = rr.age * 10;
              return of(rr);
            } else {
              this.client
                .get('https://api.coindesk.com/v1/bpi/currentprice.json')
                .pipe(
                  map((res) => {
                    console.log(res);
                    rr.age = rr.age * 10000;
                    return rr;
                  })
                );
            }
          })
        ).pipe(
          map((paths) => {
            console.log('w');
            console.log(paths);
            return paths;
            // return result.map((e, index) => ({
            //   age: paths[index],
            // }));
          })
        );
      })
    );
  }
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The issue in your code is that you are using a condition inside your .map. If you are using a condition in .map function, you need to add return because as the error states that a stream was expected instead of undefined. In order for you to provide an observable, you need to return your observable inside your if-else condition.

In the code below, I added the keyword return on your of() and on your http call. I also created a stackblitz containing my solution for you to check.

test2(): Observable < Student[] > {
  return this.test1().pipe(
    mergeMap((result) => {
      if (!result) {
        return of(result);
      }
      return forkJoin(
        result.map((rr) => {
          if (rr.age === 1) {
            rr.age = rr.age * 10;
            return of(rr);
          } else {
            return this.client
              .get('https://api.coindesk.com/v1/bpi/currentprice.json')
              .pipe(
                map((res) => {
                  console.log(res);
                  rr.age = rr.age * 10000;
                  return rr;
                })
              );
          }
        })
      ).pipe(
        map((paths) => {
          console.log('w');
          console.log(paths);
          return paths;
        })
      );
    })
  );
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda