Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
¿Límite de tubería observable y angular?

Estoy haciendo esto en uno de mis guardias de ruta...

 canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { // go through each check sequentially, stop process if one does throwError return of(true).pipe( // Is there a limit to operators in a pipe??? switchMap(() => of(true)), // simplified for this post...usually call a function that returns switchMap(() => of(true)), switchMap(() => of(true)), switchMap(() => of(true)), switchMap(() => of(true)), switchMap(() => of(true)), switchMap(() => of(true)), switchMap(() => of(true)), // if any function returns throwError, we skip other checks catchError(() => of(false)) ); }

Me estoy encontrando con un error. Si hay un switchMap más agregado a la lista, VSCode me dice... "El tipo 'Observable<{}>' no se puede asignar al tipo 'Observable'. El tipo '{}' no se puede asignar al tipo 'boolean'.ts (2322)"

¿Alguien puede explicarme por qué es así? No puedo resolverlo y encontrar problemas relacionados.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Esto está bastante bien explicado en este problema de github .

La esencia de esto es que solo se admiten 9 operadores; más y volverá a escribir Observable<{}> ya que tienen que escribir todo manualmente hasta 9 operadores.

Use múltiples tuberías (mantiene typesafety después de la novena entrada)

Si aún desea mantener la seguridad de tipos pero agrega más de 9 operadores, simplemente llame a la función de canalización nuevamente.

 source$ .pipe( tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}) ) .pipe( // Add the next operators after the 9nth here tap(() => {}) )

Afirmar manualmente el tipo resultante

Alternativamente, puede agregar una afirmación de tipo manual al final. Sin embargo, tenga cuidado: después del noveno operador, el tipo se inferirá como Observable<{}> , perdiendo efectivamente la seguridad de tipos.

 const source$:Observable<boolean> = of(true) .pipe( tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), tap(() => {}), // Typesafety is lost here tap(() => {}), tap(() => {}), // Manually assert the type at the end // Beware that the compiler will allow pretty much anything here, // so "as Observable<string>" would work, even though it'd be wrong. ) as Observable<boolean>;
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!