Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type 'Observable<UI[] | Promise<any>>' is not assignable to type 'Observable<UI[]>'. Type 'UI[] | Promise<any>' is not assignable to type 'UI[]'

I need to return a list of UI and I do this method:

getList(): Observable<UI[]> { 
        return this.httpClient.get("/api/listui").pipe(map(
            (response:Response) => {  return response.json(); },
        ),
            catchError((error) => { return throwError(error); }));
    }

In my vs code the error appears as:

"Type 'Observable<UI[] | Promise<any>>' is not assignable to type 'Observable<UI[]>'. Type 'UI[] | Promise<any>' is not assignable to type 'UI[]'."

Anyone can help to resolve this?

like image 597
poopp Avatar asked Dec 18 '25 09:12

poopp


1 Answers

httpClient will return json data by default you don't need to do this return response.json();

getList(): Observable<UI[]> { 
        return this.httpClient.get("/api/listui").pipe(
            catchError((error) => { return throwError(error); }));
    }

like image 93
Muhammed Albarmavi Avatar answered Dec 20 '25 06:12

Muhammed Albarmavi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!