Skip to content

Commit

Permalink
chore: remove more ts-expect-error
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfy1339 committed Nov 15, 2023
1 parent 0217b65 commit f65443d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ export function throttling(octokit: Octokit, octokitOptions: OctokitOptions) {
}
});

// @ts-expect-error

Check failure on line 190 in src/index.ts

View workflow job for this annotation

GitHub Actions / test

Unused '@ts-expect-error' directive.
// The types for `before-after-hook` do not let us only pass through a Promise return value
// the types expect that the function can return either a Promise of the response, or diectly return the response.
// This is due to the fact that `@octokit/request` uses aysnc functions
// Also, since we add the custom `retryCount` property to the request argument, the types are not compatible.
octokit.hook.wrap("request", wrapRequest.bind(null, state));

return {};
Expand Down
13 changes: 5 additions & 8 deletions src/wrap-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@ const noop = () => Promise.resolve();

export function wrapRequest(
state: State,
request: (
request: ((
options: Required<EndpointDefaults>,
) => OctokitResponse<any> | Promise<OctokitResponse<any>>,
) => Promise<OctokitResponse<any>>) & { retryCount: number },
options: Required<EndpointDefaults>,
) {
return state.retryLimiter.schedule(doRequest, state, request, options);
}

async function doRequest(
state: State,
request: (
request: ((
options: Required<EndpointDefaults>,
) => OctokitResponse<any> | Promise<OctokitResponse<any>>,
) => Promise<OctokitResponse<any>>) & { retryCount: number },
options: Required<EndpointDefaults>,
) {
const isWrite = options.method !== "GET" && options.method !== "HEAD";
const { pathname } = new URL(options.url, "http://github.test");
const isSearch = options.method === "GET" && pathname.startsWith("/search/");
const isGraphQL = pathname.startsWith("/graphql");

// @ts-expect-errors
const retryCount = ~~request.retryCount;
const jobOptions = retryCount > 0 ? { priority: 0, weight: 0 } : {};
if (state.clustering) {
Expand Down Expand Up @@ -55,7 +54,6 @@ async function doRequest(
.key(state.id)
.schedule<OctokitResponse<any>, Required<EndpointDefaults>>(
jobOptions,
// @ts-expect-error
request,
options,
);
Expand All @@ -64,8 +62,7 @@ async function doRequest(

if (
res.data.errors != null &&
// @ts-expect-error
res.data.errors.some((error) => error.type === "RATE_LIMITED")
res.data.errors.some((error: any) => error.type === "RATE_LIMITED")
) {
const error = Object.assign(new Error("GraphQL Rate Limit Exceeded"), {
response: res,
Expand Down

0 comments on commit f65443d

Please sign in to comment.