Skip to content

Commit ed06bcc

Browse files
committed
make type accurate
1 parent 7fd4fab commit ed06bcc

File tree

1 file changed

+59
-14
lines changed

1 file changed

+59
-14
lines changed

http/index.ts

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -119,80 +119,125 @@ function addQueryParams(
119119
};
120120
}
121121

122+
async function getRequest<T>(
123+
accountId: number,
124+
options: HttpOptions
125+
): Promise<T>;
122126
async function getRequest<T>(
123127
accountId: number,
124128
options: HttpOptions,
125-
withFullResponse = false
126-
): Promise<T> {
129+
withFullResponse: true
130+
): Promise<AxiosResponse<T>>;
131+
async function getRequest<T>(
132+
accountId: number,
133+
options: HttpOptions,
134+
withFullResponse?: true
135+
) {
127136
const { params, ...rest } = options;
128137
const axiosConfig = addQueryParams(rest, params);
129138
const configWithAuth = await withAuth(accountId, axiosConfig);
130139

131140
const response = await axios<T>(configWithAuth);
132141

133142
if (withFullResponse) {
134-
return response as T;
143+
return response;
135144
}
136145

137146
return response.data;
138147
}
139148

149+
async function postRequest<T>(
150+
accountId: number,
151+
options: HttpOptions
152+
): Promise<T>;
140153
async function postRequest<T>(
141154
accountId: number,
142155
options: HttpOptions,
143-
withFullResponse = false
144-
): Promise<T> {
156+
withFullResponse: true
157+
): Promise<AxiosResponse<T>>;
158+
async function postRequest(
159+
accountId: number,
160+
options: HttpOptions,
161+
withFullResponse?: true
162+
) {
145163
const configWithAuth = await withAuth(accountId, options);
146164

147165
const response = await axios({ ...configWithAuth, method: 'post' });
148166

149167
if (withFullResponse) {
150-
return response as T;
168+
return response;
151169
}
152170

153171
return response.data;
154172
}
155173

174+
async function putRequest<T>(
175+
accountId: number,
176+
options: HttpOptions
177+
): Promise<T>;
156178
async function putRequest<T>(
157179
accountId: number,
158180
options: HttpOptions,
159-
withFullResponse = false
160-
): Promise<T> {
181+
withFullResponse: true
182+
): Promise<AxiosResponse<T>>;
183+
async function putRequest(
184+
accountId: number,
185+
options: HttpOptions,
186+
withFullResponse?: true
187+
) {
161188
const configWithAuth = await withAuth(accountId, options);
162189
const response = await axios({ ...configWithAuth, method: 'put' });
163190

164191
if (withFullResponse) {
165-
return response as T;
192+
return response;
166193
}
167194

168195
return response.data;
169196
}
170197

198+
async function patchRequest<T>(
199+
accountId: number,
200+
options: HttpOptions
201+
): Promise<T>;
171202
async function patchRequest<T>(
172203
accountId: number,
173204
options: HttpOptions,
174-
withFullResponse = false
175-
): Promise<T> {
205+
withFullResponse: true
206+
): Promise<AxiosResponse<T>>;
207+
async function patchRequest(
208+
accountId: number,
209+
options: HttpOptions,
210+
withFullResponse?: true
211+
) {
176212
const configWithAuth = await withAuth(accountId, options);
177213
const response = await axios({ ...configWithAuth, method: 'patch' });
178214

179215
if (withFullResponse) {
180-
return response as T;
216+
return response;
181217
}
182218

183219
return response.data;
184220
}
185221

186222
async function deleteRequest<T>(
223+
accountId: number,
224+
options: HttpOptions
225+
): Promise<T>;
226+
async function deleteRequest<T>(
227+
accountId: number,
228+
options: HttpOptions,
229+
withFullResponse: true
230+
): Promise<AxiosResponse<T>>;
231+
async function deleteRequest(
187232
accountId: number,
188233
options: HttpOptions,
189234
withFullResponse = false
190-
): Promise<T> {
235+
) {
191236
const configWithAuth = await withAuth(accountId, options);
192237
const response = await axios({ ...configWithAuth, method: 'delete' });
193238

194239
if (withFullResponse) {
195-
return response as T;
240+
return response;
196241
}
197242

198243
return response.data;

0 commit comments

Comments
 (0)