[v2.1.1] fix axios type bug
This commit is contained in:
parent
377e34deb5
commit
272269339e
3 changed files with 11 additions and 9 deletions
|
@ -608,6 +608,8 @@ interface Task {
|
||||||
This tool only supports `application/json` type for request and response body. Any other type like `multipart/form` or `image/*` are **not supported** and will be ignored.
|
This tool only supports `application/json` type for request and response body. Any other type like `multipart/form` or `image/*` are **not supported** and will be ignored.
|
||||||
|
|
||||||
## Versions
|
## Versions
|
||||||
|
#### 2.1.1
|
||||||
|
- Fix axios type bug (`AxiosPromise` vs `Promise<AxiosResponse>`)
|
||||||
#### 2.1.0
|
#### 2.1.0
|
||||||
- Move `@sup39/api-ts-gen/utils` to `@sup39/api-ts-gen/dist/utils` since symlink is no longer allowed
|
- Move `@sup39/api-ts-gen/utils` to `@sup39/api-ts-gen/dist/utils` since symlink is no longer allowed
|
||||||
- Simplify `apiRouter.ts` by using `router.use` to check for `BadValueError`
|
- Simplify `apiRouter.ts` by using `router.use` to check for `BadValueError`
|
||||||
|
|
10
dist/utils/APIPromise.d.ts
vendored
10
dist/utils/APIPromise.d.ts
vendored
|
@ -1,21 +1,21 @@
|
||||||
import { AxiosResponse } from 'axios';
|
import { AxiosPromise, AxiosResponse } from 'axios';
|
||||||
declare type ValueOf<T> = T[keyof T];
|
declare type ValueOf<T> = T[keyof T];
|
||||||
declare type RHandler<T> = ValueOf<{
|
declare type RHandler<T> = ValueOf<{
|
||||||
[K in keyof T]: T[K] extends (data: any) => infer U ? U : never;
|
[K in keyof T]: T[K] extends (data: any) => infer U ? U : never;
|
||||||
}>;
|
}>;
|
||||||
export declare class BadResponseError extends Error {
|
export declare class BadResponseError extends Error {
|
||||||
res: AxiosResponse<any>;
|
res: AxiosResponse;
|
||||||
constructor(res: AxiosResponse<any>, label: string);
|
constructor(res: AxiosResponse, label: string);
|
||||||
}
|
}
|
||||||
export declare class APIPromise<TRes, KRsv extends keyof TRes, THdl extends {
|
export declare class APIPromise<TRes, KRsv extends keyof TRes, THdl extends {
|
||||||
[K in KRsv]: (data: TRes[K]) => any;
|
[K in KRsv]: (data: TRes[K]) => any;
|
||||||
}, KOn extends keyof TRes = keyof TRes> implements PromiseLike<RHandler<THdl>> {
|
}, KOn extends keyof TRes = keyof TRes> implements PromiseLike<RHandler<THdl>> {
|
||||||
private handlers;
|
private handlers;
|
||||||
private promise;
|
private promise;
|
||||||
constructor(resPromise: Promise<AxiosResponse>, stps: {
|
constructor(resPromise: AxiosPromise, stps: {
|
||||||
[K in keyof TRes]: (data: any) => TRes[K];
|
[K in keyof TRes]: (data: any) => TRes[K];
|
||||||
}, handlers: THdl);
|
}, handlers: THdl);
|
||||||
static init<TRes, KRsv extends keyof TRes>(res: Promise<AxiosResponse>, stps: {
|
static init<TRes, KRsv extends keyof TRes>(res: AxiosPromise, stps: {
|
||||||
[K in keyof TRes]: (data: any) => TRes[K];
|
[K in keyof TRes]: (data: any) => TRes[K];
|
||||||
}, kRsvs: KRsv[]): APIPromise<TRes, KRsv, {
|
}, kRsvs: KRsv[]): APIPromise<TRes, KRsv, {
|
||||||
[K in KRsv]: (data: TRes[K]) => TRes[K];
|
[K in KRsv]: (data: TRes[K]) => TRes[K];
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import {AxiosResponse} from 'axios';
|
import {AxiosPromise, AxiosResponse} from 'axios';
|
||||||
|
|
||||||
type ValueOf<T> = T[keyof T];
|
type ValueOf<T> = T[keyof T];
|
||||||
type RHandler<T> = ValueOf<{[K in keyof T]:
|
type RHandler<T> = ValueOf<{[K in keyof T]:
|
||||||
|
@ -11,7 +11,7 @@ function typeGuard<T extends U, U=any>(checker: (x: U) => boolean) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BadResponseError extends Error {
|
export class BadResponseError extends Error {
|
||||||
constructor(public res: AxiosResponse<any>, label: string) {
|
constructor(public res: AxiosResponse, label: string) {
|
||||||
super(`${label} status code: ${res.status}\ndata: ${
|
super(`${label} status code: ${res.status}\ndata: ${
|
||||||
typeof res.data === 'object' ? JSON.stringify(res.data) : res.data}`);
|
typeof res.data === 'object' ? JSON.stringify(res.data) : res.data}`);
|
||||||
Object.setPrototypeOf(this, BadResponseError.prototype);
|
Object.setPrototypeOf(this, BadResponseError.prototype);
|
||||||
|
@ -27,7 +27,7 @@ export class APIPromise<
|
||||||
private promise: Promise<RHandler<THdl>>;
|
private promise: Promise<RHandler<THdl>>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
resPromise: Promise<AxiosResponse>,
|
resPromise: AxiosPromise,
|
||||||
stps: {[K in keyof TRes]: (data: any) => TRes[K]},
|
stps: {[K in keyof TRes]: (data: any) => TRes[K]},
|
||||||
private handlers: THdl,
|
private handlers: THdl,
|
||||||
) {
|
) {
|
||||||
|
@ -48,7 +48,7 @@ export class APIPromise<
|
||||||
}
|
}
|
||||||
|
|
||||||
static init<TRes, KRsv extends keyof TRes>(
|
static init<TRes, KRsv extends keyof TRes>(
|
||||||
res: Promise<AxiosResponse>,
|
res: AxiosPromise,
|
||||||
stps: {[K in keyof TRes]: (data: any) => TRes[K]},
|
stps: {[K in keyof TRes]: (data: any) => TRes[K]},
|
||||||
kRsvs: KRsv[],
|
kRsvs: KRsv[],
|
||||||
): APIPromise<
|
): APIPromise<
|
||||||
|
|
Reference in a new issue