Property 'map' does not exist on type 'AxiosResponse<any>'.ts(2339)

Viewed 13999

My map function in this code block:

public async getAllWidgets2(): Promise<Widget[]> {

    let url = "myUrl";

    var items = [];

     return axios.get(url).then(result => {

        console.log("results" + result)

        let result2: Widget[] = [];
        result.map((item) => { result2.push(this.parseWidget(item)); });
        let data: Widget[] = result2;
        return(data);


    } ) }

The map functions above gives me an error "Property 'map' does not exist on type 'AxiosResponse'.ts(2339)"

I searched on answers on StackOverflow and tried:

import { map } from 'rxjs/operators';

But still gives me the same error. Any way to solve it?

1 Answers

Axios Response does not only contain the response body, it is an object containing all the details about the request, the response, etc...

If you want to map the response body (data), you have to do all of this on 'response.data' and not 'response' :)

Related