简体   繁体   English

“AxiosResponse”类型上不存在属性“地图”<any> '.ts(2339)</any>

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

My map function in this code block:我的 map function 在这个代码块中:

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)"上面的 map 函数给我一个错误“属性 'map' 在类型 'AxiosResponse'.ts(2339) 上不存在”

I searched on answers on StackOverflow and tried:我在 StackOverflow 上搜索了答案并尝试了:

import { map } from 'rxjs/operators';

But still gives me the same error.但仍然给我同样的错误。 Any way to solve it?有什么办法解决吗?

Axios Response does not only contain the response body, it is an object containing all the details about the request, the response, etc... Axios 响应不仅包含响应主体,它还是一个 object 包含有关请求、响应等的所有详细信息...

If you want to map the response body (data), you have to do all of this on 'response.data' and not 'response':)如果您想 map 响应正文(数据),您必须在 'response.data' 而不是 'response' 上执行所有这些操作:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 类型“ AxiosResponse”上不存在属性“数据” <any> | 未定义” - Property 'data' does not exist on type 'AxiosResponse<any> | undefined' 对象数组上的 Map(错误:属性“map”在类型“{}”上不存在。TS2339) - Map on array of objects (Error: Property 'map' does not exist on type '{}'. TS2339) 错误TS2339:类型'Observable <Response>'上不存在属性'map' - error TS2339: Property 'map' does not exist on type 'Observable<Response>' 将 class 转换为挂钩获取属性 'then' 在类型 '(dispatch: any) => Promise 上不存在<void> '.ts(2339)</void> - converting class to hooks getting Property 'then' does not exist on type '(dispatch: any) => Promise<void>'.ts(2339) TS2339:类型“ {}”上不存在属性“ props” - TS2339: Property 'props' does not exist on type '{}' 错误TS2339:类型“字符串”上不存在属性“默认”。** - Error TS2339: Property 'Default' does not exist on type 'string'.** 属性“模块”在类型“ typeof MyEditor”上不存在。ts(2339) - Property 'modules' does not exist on type 'typeof MyEditor'.ts(2339) Typescript 通用:“T”类型上不存在属性“pass”.ts(2339) - Typescript generic : Property 'pass' does not exist on type 'T'.ts(2339) 类型 'void | 上不存在属性 'subscribe' 可观察的<user> '。 ts(2339)</user> - Property 'subscribe' does not exist on type 'void | Observable<User>'. ts(2339) TS2339:“元素”类型上不存在属性“样式” - TS2339: Property 'style' does not exist on type 'Element'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM