Skip to content

Commit d77e6f3

Browse files
committed
🐛 Fix: types bug
1 parent 75f0742 commit d77e6f3

File tree

3 files changed

+15
-14
lines changed

3 files changed

+15
-14
lines changed

src/lib/Request.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable @typescript-eslint/explicit-function-return-type */
22
/* eslint-disable @typescript-eslint/promise-function-async */
3-
import axios, { AxiosRequestConfig } from 'axios'
4-
import { IPicGo, Undefinable, IConfigChangePayload, IConfig, IRequestConfig, IOldReqOptions, IResponse, AxiosResponse, IFullResponse, IRequest } from '../types'
3+
import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'
4+
import { IPicGo, Undefinable, IConfigChangePayload, IConfig, IRequestConfig, IOldReqOptions, IResponse, IFullResponse, IRequest } from '../types'
55
import { IBusEvent } from '../utils/enum'
66
import { eventBus } from '../utils/eventBus'
77
import { URL } from 'url'

src/plugins/uploader/github.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const postOptions = (fileName: string, options: IGithubConfig, data: any): IOldR
1414
},
1515
body: data,
1616
json: true
17-
}
17+
} as const
1818
}
1919

2020
const handle = async (ctx: IPicGo): Promise<IPicGo> => {

src/types/index.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,14 @@ export interface IRequestOld {
165165

166166
export type IOldReqOptions = Omit<RequestPromiseOptions & {
167167
url: string
168-
resolveWithFullResponse?: true
169168
}, 'auth'>
170169

171170
export type IOldReqOptionsWithFullResponse = IOldReqOptions & {
172171
resolveWithFullResponse: true
173172
}
174173

175174
export type IOldReqOptionsWithJSON = IOldReqOptions & {
176-
json: boolean
175+
json: true
177176
}
178177

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

203-
export type AxiosResponse<T = any, U = any> = import('axios').AxiosResponse<T, U>
202+
type AxiosResponse<T = any, U = any> = import('axios').AxiosResponse<T, U>
204203

205-
export type AxiosRequestConfig<T = any> = import('axios').AxiosRequestConfig<T>
204+
type AxiosRequestConfig<T = any> = import('axios').AxiosRequestConfig<T>
206205

207206
interface IRequestOptionsWithFullResponse {
208207
resolveWithFullResponse: true
209208
}
210209

211-
interface IRequestOptionsWithJson {
210+
interface IRequestOptionsWithJSON {
212211
json: true
213212
}
214213

@@ -220,12 +219,14 @@ interface IRequestOptionsWithResponseTypeArrayBuffer {
220219
* T is the response data type
221220
* U is the config type
222221
*/
223-
export type IResponse<T, U> = U extends IRequestOptionsWithFullResponse
224-
? IFullResponse<T, U>
225-
: U extends IRequestOptionsWithJson
226-
? T
227-
: U extends IRequestOptionsWithResponseTypeArrayBuffer ?
228-
Buffer : string
222+
export type IResponse<T, U> = U extends IRequestOptionsWithFullResponse ? IFullResponse<T, U>
223+
: U extends IRequestOptionsWithJSON ? T
224+
: U extends IRequestOptionsWithResponseTypeArrayBuffer ? Buffer
225+
: U extends IOldReqOptionsWithFullResponse ? IFullResponse<T, U>
226+
: U extends IOldReqOptionsWithJSON ? T
227+
: U extends IOldReqOptions ? string
228+
: U extends IReqOptionsWithBodyResOnly ? T
229+
: string
229230

230231
/**
231232
* the old request lib will be removed in v1.5.0+

0 commit comments

Comments
 (0)