From d77e6f3b8d580ea6c3f69c001f0f05aa34c8a7af Mon Sep 17 00:00:00 2001 From: PiEgg Date: Fri, 14 Oct 2022 15:43:24 +0800 Subject: [PATCH] :bug: Fix: types bug --- src/lib/Request.ts | 4 ++-- src/plugins/uploader/github.ts | 2 +- src/types/index.ts | 23 ++++++++++++----------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/lib/Request.ts b/src/lib/Request.ts index d1550b9..93b1944 100644 --- a/src/lib/Request.ts +++ b/src/lib/Request.ts @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/explicit-function-return-type */ /* eslint-disable @typescript-eslint/promise-function-async */ -import axios, { AxiosRequestConfig } from 'axios' -import { IPicGo, Undefinable, IConfigChangePayload, IConfig, IRequestConfig, IOldReqOptions, IResponse, AxiosResponse, IFullResponse, IRequest } from '../types' +import axios, { AxiosRequestConfig, AxiosResponse } from 'axios' +import { IPicGo, Undefinable, IConfigChangePayload, IConfig, IRequestConfig, IOldReqOptions, IResponse, IFullResponse, IRequest } from '../types' import { IBusEvent } from '../utils/enum' import { eventBus } from '../utils/eventBus' import { URL } from 'url' diff --git a/src/plugins/uploader/github.ts b/src/plugins/uploader/github.ts index 0342185..ce17e83 100644 --- a/src/plugins/uploader/github.ts +++ b/src/plugins/uploader/github.ts @@ -14,7 +14,7 @@ const postOptions = (fileName: string, options: IGithubConfig, data: any): IOldR }, body: data, json: true - } + } as const } const handle = async (ctx: IPicGo): Promise => { diff --git a/src/types/index.ts b/src/types/index.ts index 9a50340..beda3a1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -165,7 +165,6 @@ export interface IRequestOld { export type IOldReqOptions = Omit export type IOldReqOptionsWithFullResponse = IOldReqOptions & { @@ -173,7 +172,7 @@ export type IOldReqOptionsWithFullResponse = IOldReqOptions & { } export type IOldReqOptionsWithJSON = IOldReqOptions & { - json: boolean + json: true } /** @@ -200,15 +199,15 @@ export type IFullResponse = AxiosResponse & { body: T } -export type AxiosResponse = import('axios').AxiosResponse +type AxiosResponse = import('axios').AxiosResponse -export type AxiosRequestConfig = import('axios').AxiosRequestConfig +type AxiosRequestConfig = import('axios').AxiosRequestConfig interface IRequestOptionsWithFullResponse { resolveWithFullResponse: true } -interface IRequestOptionsWithJson { +interface IRequestOptionsWithJSON { json: true } @@ -220,12 +219,14 @@ interface IRequestOptionsWithResponseTypeArrayBuffer { * T is the response data type * U is the config type */ -export type IResponse = U extends IRequestOptionsWithFullResponse - ? IFullResponse - : U extends IRequestOptionsWithJson - ? T - : U extends IRequestOptionsWithResponseTypeArrayBuffer ? - Buffer : string +export type IResponse = U extends IRequestOptionsWithFullResponse ? IFullResponse + : U extends IRequestOptionsWithJSON ? T + : U extends IRequestOptionsWithResponseTypeArrayBuffer ? Buffer + : U extends IOldReqOptionsWithFullResponse ? IFullResponse + : U extends IOldReqOptionsWithJSON ? T + : U extends IOldReqOptions ? string + : U extends IReqOptionsWithBodyResOnly ? T + : string /** * the old request lib will be removed in v1.5.0+