Coder Social home page Coder Social logo

ts-axios's Introduction

项目介绍

用 typescript 实现 axios 浏览器部分,完善的 demo 与单元测试

ts-axios

  • 采用 Promise API
  • 请求和响应配置化
  • 支持请求和响应数据自定义拦截器
  • 支持外部取消请求
  • 支持跨域请求携带 cookie
  • 支持客户端 XSRF 防御
  • 支持 upload/download 进度监控
  • 支持 http authorization
  • 自定义合法状态码
  • 自定义参数序列化
  • 支持配置 baseURL
  • axios.all axios.spread axios.getUri

所有 axios 官方库浏览器端功能已实现

单元测试

  • helpers 模块测试用例编写完毕

ts-axios's People

Contributors

yishibakaien avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ts-axios's Issues

请教个问题

// 链式调用
    const chian: PromiseChian[] = [{
      resolve: dispatchRequest,
      rejected: undefined
    }]

    this.interceptors.request.forEach(interceptor => {
      chian.unshift(interceptor)
    })

    this.interceptors.response.forEach(interceptor => {
      chian.push(interceptor)
    })

    let promise = Promise.resolve(config)
    while (chian.length) {
      const { resolve, rejected } = chian.shift()!
      promise = promise.then(resolve, rejected)
    }

    // return dispatchRequest(config)
    return promise

我返回的 promise, 编辑器提示我错误

不能将类型“Promise<AxiosRequest>”分配给类型“AxiosPromise<any>”。
  属性“then”的类型不兼容。
    不能将类型“<TResult1 = AxiosRequest, TResult2 = never>(onfulfilled?: ((value: AxiosRequest) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<...>”分配给类型“<TResult1 = AxiosResponse<any>, TResult2 = never>(onfulfilled?: ((value: AxiosResponse<any>) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | null | undefined) => Promise<...>”。
      参数“onfulfilled”和“onfulfilled” 的类型不兼容。
        参数“value”和“value” 的类型不兼容。
          Type 'AxiosRequest' is missing the following properties from type 'AxiosResponse<any>': status, config, statusText, requestts(2322)

请问你在写的时候遇到过这样的问题吗

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.