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

146
Views
Angular/Typescript actualizado ahora recibe el error de Tipo 'Observable<desconocido>' no se puede asignar al tipo 'Observable<ProcResult[]>'

He tenido mi servicio de base de datos en Angular configurado de esta manera desde Angular 6 y me encuentro con este error por primera vez.

Tengo un HTTP POST estándar que devuelve un resultado. En el caso de un error, quiero que se maneje el error. El error más probable es simplemente un token caducado, así que lo manejo específicamente para cerrar la sesión del usuario.

CORREO

 postUsp(username): Observable<ProcResult[]> { const url = hosturl +'u_sp'; const httpOptions = { headers: new HttpHeaders({ 'Access-Control-Allow-Origin': '*', 'Content-Type': 'application/json', 'Authorization': ls || '{}' }), withCredentials: true, params: { 'username': username, } }; return this._http.post<ProcResult[]>(url, null, httpOptions) .pipe( map((res) => { return <ProcResult[]> res; }), catchError(this.handleError) ) }

handleError

 private handleError(error: Response | any) { if (error.status === 401) { console.log('Signing out.') try { Auth.signOut().then(() => { window.location.reload() }) return error } catch (error) { console.log('error signing out: ', error); } } else { return throwError(error); } }

Salida de error completa:

 Error: src/app/db.service.ts:303:3 - error TS2322: Type 'Observable<unknown>' is not assignable to type 'Observable<ProcResult[]>'. Type 'unknown' is not assignable to type 'ProcResult[]'. 303 return this._http.post<ProcResult[]>(url, null, httpOptions) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 304 .pipe( ~~~~~~~~ ... 309 catchError(this.handleError) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 310 )
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Tienes que agregar throwError en el bloque try and catch .

 private handleError(error: Response | any) { if (error.status === 401) { console.log('Signing out.'); try { Auth.signOut().then(() => { window.location.reload() }) return throwError(error); } catch (error) { console.log('error signing out: ', error); return throwError(error); } } else { return throwError(error); } }
about 4 years ago · Juan Pablo Isaza 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!