From 272269339ec3183bd5f8f1509cb87415e725f799 Mon Sep 17 00:00:00 2001 From: sup39 Date: Mon, 13 Jun 2022 21:06:21 +0900 Subject: [PATCH] [v2.1.1] fix axios type bug --- README.md | 2 ++ dist/utils/APIPromise.d.ts | 10 +++++----- lib/utils/APIPromise.ts | 8 ++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 3250f93..78c2165 100644 --- a/README.md +++ b/README.md @@ -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. ## Versions +#### 2.1.1 +- Fix axios type bug (`AxiosPromise` vs `Promise`) #### 2.1.0 - 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` diff --git a/dist/utils/APIPromise.d.ts b/dist/utils/APIPromise.d.ts index df7455e..d0268cf 100644 --- a/dist/utils/APIPromise.d.ts +++ b/dist/utils/APIPromise.d.ts @@ -1,21 +1,21 @@ -import { AxiosResponse } from 'axios'; +import { AxiosPromise, AxiosResponse } from 'axios'; declare type ValueOf = T[keyof T]; declare type RHandler = ValueOf<{ [K in keyof T]: T[K] extends (data: any) => infer U ? U : never; }>; export declare class BadResponseError extends Error { - res: AxiosResponse; - constructor(res: AxiosResponse, label: string); + res: AxiosResponse; + constructor(res: AxiosResponse, label: string); } export declare class APIPromise any; }, KOn extends keyof TRes = keyof TRes> implements PromiseLike> { private handlers; private promise; - constructor(resPromise: Promise, stps: { + constructor(resPromise: AxiosPromise, stps: { [K in keyof TRes]: (data: any) => TRes[K]; }, handlers: THdl); - static init(res: Promise, stps: { + static init(res: AxiosPromise, stps: { [K in keyof TRes]: (data: any) => TRes[K]; }, kRsvs: KRsv[]): APIPromise TRes[K]; diff --git a/lib/utils/APIPromise.ts b/lib/utils/APIPromise.ts index 0fdf439..b16c3fe 100644 --- a/lib/utils/APIPromise.ts +++ b/lib/utils/APIPromise.ts @@ -1,4 +1,4 @@ -import {AxiosResponse} from 'axios'; +import {AxiosPromise, AxiosResponse} from 'axios'; type ValueOf = T[keyof T]; type RHandler = ValueOf<{[K in keyof T]: @@ -11,7 +11,7 @@ function typeGuard(checker: (x: U) => boolean) { } export class BadResponseError extends Error { - constructor(public res: AxiosResponse, label: string) { + constructor(public res: AxiosResponse, label: string) { super(`${label} status code: ${res.status}\ndata: ${ typeof res.data === 'object' ? JSON.stringify(res.data) : res.data}`); Object.setPrototypeOf(this, BadResponseError.prototype); @@ -27,7 +27,7 @@ export class APIPromise< private promise: Promise>; constructor( - resPromise: Promise, + resPromise: AxiosPromise, stps: {[K in keyof TRes]: (data: any) => TRes[K]}, private handlers: THdl, ) { @@ -48,7 +48,7 @@ export class APIPromise< } static init( - res: Promise, + res: AxiosPromise, stps: {[K in keyof TRes]: (data: any) => TRes[K]}, kRsvs: KRsv[], ): APIPromise<