Skip to content
Myr

Fix some TypeScript TODOs (#355)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Luka Jeran · committed by GitHub · parent 757cd0a · Browse files · 4 files+30 added−29 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+30 added−29 removed

  • tests:+2 added−1 removed
  • other:+28 added−28 removed

4 files+30 added−29 removed

modified:source/core/Ky.ts+6 added-6 removed
144 unmodified lines
145 return response;146 };147148 const isRetriableMethod = ky._options.retry.methods.includes(ky.request.method.toLowerCase());149 const result = isRetriableMethod ? ky._retry(fn) : fn();149 const result = (isRetriableMethod ? ky._retry(fn) : fn()) as ResponsePromise;150151 for (const [type, mimeType] of Object.entries(responseTypes)) {152 // @ts-expect-error not sure how to properly type this!151 for (const entry of Object.entries(responseTypes)) {152 const [type, mimeType] = entry as [keyof typeof responseTypes, string];153154 result[type] = async () => {155 // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing156 ky.request.headers.set('accept', ky.request.headers.get('accept') || mimeType);157157 const response = ((await result) as Response).clone();158 const response = (await result).clone();159160 if (type === 'json') {161 if (response.status === 204) {162 return '';
3 unmodified lines
166 return options.parseJson(await response.text());167 }168 }169169 // @ts-expect-error not sure how to properly type this!170 return response[type]();171 };172 }173174 return result as ResponsePromise;174 return result;175 }176177 protected _calculateRetryDelay(error: Error) {178 this._retryCount++;
136 unmodified lines
modified:source/types/ky.ts+18 added-18 removed
modified:source/index.ts+4 added-4 removed
modified:test/hooks.ts+2 added-1 removed
268 unmodified lines
269 .post(server.url, {270 json,271 hooks: {272 afterResponse: [273 // @ts-expect-error273 async (request, options, response) => {274 if (response.status === 403) {275 // Retry request with valid token276 return ky(request, {
4 unmodified lines
281 token: 'valid:token'282 }283 });284 }285286 return undefined;287 }288 ]289 }290 })
315 unmodified lines