Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bump typescript and fix errors #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import { normalizeURL } from "./lib/utils";
import { merge } from "./lib/merge";

export type DefaultGretchResponse = any;

Check warning on line 11 in index.ts

View workflow job for this annotation

GitHub Actions / Pre-release

Unexpected any. Specify a different type
export type DefaultGretchError = any;

Check warning on line 12 in index.ts

View workflow job for this annotation

GitHub Actions / Pre-release

Unexpected any. Specify a different type

export type MergeableObject =
| {
[k: string]: MergeableObject;
}
| Partial<GretchOptions>
| any[];

Check warning on line 19 in index.ts

View workflow job for this annotation

GitHub Actions / Pre-release

Unexpected any. Specify a different type

export type GretchResponse<T = DefaultGretchResponse, A = DefaultGretchError> =
| {
Expand Down Expand Up @@ -47,13 +47,13 @@

export type GretchOptions = {
baseURL?: string;
json?: { [key: string]: any };

Check warning on line 50 in index.ts

View workflow job for this annotation

GitHub Actions / Pre-release

Unexpected any. Specify a different type
retry?: RetryOptions | boolean;
timeout?: number;
onException?: (e: Error) => void;
hooks?: GretchHooks;
headers?: { [key: string]: any } & RequestInit["headers"];

Check warning on line 55 in index.ts

View workflow job for this annotation

GitHub Actions / Pre-release

Unexpected any. Specify a different type
[key: string]: any;

Check warning on line 56 in index.ts

View workflow job for this annotation

GitHub Actions / Pre-release

Unexpected any. Specify a different type
} & RequestInit;

export type GretchInstance<T, A> = {
Expand Down Expand Up @@ -84,7 +84,7 @@
...(rest as RequestInit),
};
const controller =
typeof AbortController !== "undefined" ? new AbortController() : null;
typeof AbortController !== "undefined" ? new AbortController() : undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TS didn't like an optional param (evals to Type | undefined) being potentially null


if (controller) {
options.signal = controller.signal;
Expand All @@ -104,7 +104,9 @@
const request = new Request(normalizedURL, options);

if (hooks.before)
[].concat(hooks.before).forEach((hook) => hook(request, opts));
([] as GretchBeforeHook[])
.concat(hooks.before)
.forEach((hook) => hook(request, opts));
Comment on lines +107 to +109
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just flattening an array and iterating over it


const fetcher = () =>
timeout
Expand Down Expand Up @@ -148,7 +150,7 @@
error = (resolved || new HTTPError(response)) as A;
}
} catch (e) {
error = (e || `You tried to make fetch happen, but it didn't.`) as any;

Check warning on line 153 in index.ts

View workflow job for this annotation

GitHub Actions / Pre-release

Unexpected any. Specify a different type
}

const res: GretchResponse<T, A> = {
Expand All @@ -160,7 +162,9 @@
};

if (hooks.after)
[].concat(hooks.after).forEach((hook) => hook({ ...res }, opts));
([] as GretchAfterHook[])
.concat(hooks.after)
.forEach((hook) => hook({ ...res }, opts));

return res;
};
Expand Down
8 changes: 4 additions & 4 deletions lib/handleRetry.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HTTPTimeout } from "./errors";

export type RetryOptions = {
attempts?: number;
codes?: number[];
methods?: string[];
delay?: number;
attempts: number;
codes: number[];
methods: string[];
delay: number;
Comment on lines +4 to +7
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User options use Partial<RetryOptions>, and we merge in defaults, so the source type should be non-optionally typed.

};

export const defaultRetryOptions: RetryOptions = {
Expand Down
Loading