Skip to content

Commit

Permalink
🐛 Fix: types bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Oct 14, 2022
1 parent 75f0742 commit d77e6f3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/lib/Request.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/uploader/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IPicGo> => {
Expand Down
23 changes: 12 additions & 11 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,14 @@ export interface IRequestOld {

export type IOldReqOptions = Omit<RequestPromiseOptions & {
url: string
resolveWithFullResponse?: true
}, 'auth'>

export type IOldReqOptionsWithFullResponse = IOldReqOptions & {
resolveWithFullResponse: true
}

export type IOldReqOptionsWithJSON = IOldReqOptions & {
json: boolean
json: true
}

/**
Expand All @@ -200,15 +199,15 @@ export type IFullResponse<T = any, U = any> = AxiosResponse<T, U> & {
body: T
}

export type AxiosResponse<T = any, U = any> = import('axios').AxiosResponse<T, U>
type AxiosResponse<T = any, U = any> = import('axios').AxiosResponse<T, U>

export type AxiosRequestConfig<T = any> = import('axios').AxiosRequestConfig<T>
type AxiosRequestConfig<T = any> = import('axios').AxiosRequestConfig<T>

interface IRequestOptionsWithFullResponse {
resolveWithFullResponse: true
}

interface IRequestOptionsWithJson {
interface IRequestOptionsWithJSON {
json: true
}

Expand All @@ -220,12 +219,14 @@ interface IRequestOptionsWithResponseTypeArrayBuffer {
* T is the response data type
* U is the config type
*/
export type IResponse<T, U> = U extends IRequestOptionsWithFullResponse
? IFullResponse<T, U>
: U extends IRequestOptionsWithJson
? T
: U extends IRequestOptionsWithResponseTypeArrayBuffer ?
Buffer : string
export type IResponse<T, U> = U extends IRequestOptionsWithFullResponse ? IFullResponse<T, U>
: U extends IRequestOptionsWithJSON ? T
: U extends IRequestOptionsWithResponseTypeArrayBuffer ? Buffer
: U extends IOldReqOptionsWithFullResponse ? IFullResponse<T, U>
: U extends IOldReqOptionsWithJSON ? T
: U extends IOldReqOptions ? string
: U extends IReqOptionsWithBodyResOnly ? T
: string

/**
* the old request lib will be removed in v1.5.0+
Expand Down

0 comments on commit d77e6f3

Please sign in to comment.