Motivation:
- 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.
- Typed request builder can also be useful to developers who do not use Axios.
TL;DR
Current problems are:
- We can not be independent of axios, because we need
AxiosResponse generic.
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:
- 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
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.
Motivation:
TL;DR
Current problems are:
AxiosResponsegeneric.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.
PetintoAxiosResponse<Pet>).But TypeScript does not support:
ReturnTypeof generic function.So far I could not find a way around that.