Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
Updated Angular/Typescript now receiving error of Type 'Observable<unknown>' is not assignable to type 'Observable<ProcResult[]>'

I have had my database service in Angular setup this way since Angular 6 and am encountering this error for the first time.

I have a standard HTTP POST that returns a result. In the event of an error I want the error to be handled. The most likely error just being an expired token so I handle that specifically to log the user out.

POST

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

Full error output:

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 Respostas
Responde à pergunta

0

You have to add throwError in try and catch block.

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda