Coder Social home page Coder Social logo

Comments (2)

zjxxxxxxxxx avatar zjxxxxxxxxx commented on May 26, 2024

描述错误

axiosResponseData默认应该是any才对吧 在axios库中 图像

export interface AxiosResponse<T = any, D = any> {
  data: T;
  status: number;
  statusText: string;
  headers: RawAxiosResponseHeaders | AxiosResponseHeaders;
  config: InternalAxiosRequestConfig<D>;
  request?: any;
}

https://github.com/axios/axios/blob/a989ccdc1a672171e9b45d3f02edc260109a607c/index.d.ts#L378

附加上下文

没有反应

使用过的包管理器

新项目管理

验证

  • 遵守我们的行为准则
  • 阅读贡献指南
  • 阅读文档
  • 检查是否还没有报告错误的问题广东省重复。
  • 确定这是 axios-miniprogram 的问题而不是特定于框架的问题。

很高兴能够收到你的反馈。

为什么没有使用 any?

因为 axios 的类型不够严格,所以我并没有完全参考它,该库的类型定义是比 axios 更为严格的,总的来说对 axios 的类型做了补强吧。
这里不使用 any 能够更好的提醒用户,在不知道后端会返回什么样的数据时做好类型判断。
如果你知道后端会返回什样的数据,定义好类型才是更好的选择,当然也可以传入 any 泛型,忽略报错,但不太建议这样做。
另外 taro,uni-app 也都对 data 做的严格的类型定义,严格的类型限制总得来说肯定是利大于弊的,不然太容易把 TypeScript 写成 AnyScript

from axios-miniprogram.

lihanspace avatar lihanspace commented on May 26, 2024

好的谢谢

from axios-miniprogram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.