Skip to content

Commit 453efe9

Browse files
authored
fix: fetch util types (#1218)
## 🧰 Changes widens the types of these util functions a bit so they play more nicely with plugins. ## 🧬 QA & Testing i confirmed locally that these types play nicely with plugins.
1 parent b6f0f78 commit 453efe9

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/lib/readmeAPIFetch.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,12 @@ export async function readmeAPIv1Fetch(
227227
/**
228228
* Wrapper for the `fetch` API so we can add rdme-specific headers to all ReadMe API v2 requests.
229229
*/
230-
export async function readmeAPIv2Fetch(
231-
this: CommandClass['prototype'] | Hook.Context,
230+
export async function readmeAPIv2Fetch<T extends Hook.Context = Hook.Context>(
231+
/**
232+
* `this` does not have to be a hook, it can also be a Command class.
233+
* This type ensures that `this` has the `config` and `debug` properties.
234+
*/
235+
this: T,
232236
/** The pathname to make the request to. Must have a leading slash. */
233237
pathname: string,
234238
options: RequestInit = { headers: new Headers() },
@@ -367,8 +371,12 @@ export async function handleAPIv1Res(
367371
*
368372
* If we receive non-JSON responses, we consider them errors and throw them.
369373
*/
370-
export async function handleAPIv2Res(
371-
this: CommandClass['prototype'] | Hook.Context,
374+
export async function handleAPIv2Res<T extends Hook.Context = Hook.Context>(
375+
/**
376+
* `this` does not have to be a hook, it can also be a Command class.
377+
* This type ensures that `this` has the `config` and `debug` properties.
378+
*/
379+
this: T,
372380
res: Response,
373381
/**
374382
* If we're making a request where we don't care about the body (e.g. a HEAD or DELETE request),

0 commit comments

Comments
 (0)