前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Property 'xxx' does not exist on type 'Ax一文读懂TS的(.d.ts)文件iosResponse<any, any>' 的解决办法

Property 'xxx' does not exist on type 'Ax一文读懂TS的(.d.ts)文件iosResponse<any, any>' 的解决办法

作者头像
唐志远
发布2023-05-03 11:00:21
2.4K0
发布2023-05-03 11:00:21
举报
文章被收录于专栏:FE32 CodeFE32 Code

问题描述

vue3 + ts 项目中,使用axios库调接口时报了如下错误:

代码语言:javascript
复制
Property 'code' does not exist on type 'AxiosResponse<any, any>'.ts(2339)

或者遇到 Property 'xxx' does not exist on type 'AxiosResponse<any, any>'.ts(2339) 类型问题我们该如何解决呢?

解决方法

新建一个axios.d.ts文件,内容如下:

代码语言:javascript
复制
// 定义接口返回数据类型,这里根据后端返回去定义

interface resPage {
    page: number
    pageSize: number
    total: number
    hasNextPage: boolean
    pageTotal: number
}

interface itfRes<T = {}[] | {} | []> {
    code: number
    message: string | undefined
    data: T
    reason?: string
    page?: resPage
}

import * as axios from 'axios'

declare module 'axios' {
    interface AxiosResponse extends itfRes
}

加上之后的效果:

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-04-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 问题描述
  • 解决方法
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档