Skip to content

Be less dependent on axios #4

@simplesmiler

Description

@simplesmiler

Motivation:

  1. Axios does not support response streaming in browser, only in Node (there is intent, but no visible progress so far.). A readable "stream" can be acquired from Blob response, but the whole response body is buffered in memory anyways. Fetch, on the other had, supports streaming, although not in every browser.
  2. Typed request builder can also be useful to developers who do not use Axios.

TL;DR

Current problems are:

  1. We can not be independent of axios, because we need AxiosResponse generic.
  2. Axios can not be peer dependency because TypeScript does not work well with peer dependencies. Not a problem anymore, was solved by also having it as dev dependency.

Details

To be independent of axios, we have to be able to arbitrarily wrap response types (e.g. Pet into AxiosResponse<Pet>).

But TypeScript does not support:

  1. First class generics, e.g. generic as parameter for another generic.
    type Wrap<T> = { data: T };
    const taxios = new Taxios<Api, Wrap>(agent); // error: Wrap is not a type
  2. ReturnType of generic function.
    type Wrap<T> = { data: T };
    type Wrapper = <T>() => Wrap<T>;
    type WrappedNumber = ReturnType<Wrapper<number>>; // error: Wrapper is not a generic

So far I could not find a way around that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions