最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin4浏览0评论

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?

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?

Share Improve this question asked Jun 18, 2020 at 13:57 ArteArte 4172 gold badges6 silver badges16 bronze badges 1
  • 2 what is the type of result? .map() is a method on Arrays. It doesn't look like you are using rxjs, so I don't think the rxjs/operators import is needed. – joshvito Commented Jun 18, 2020 at 14:01
Add a comment  | 

1 Answer 1

Reset to default 24

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' :)

发布评论

评论列表(0)

  1. 暂无评论