-
Notifications
You must be signed in to change notification settings - Fork 5
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,15 +8,15 @@ | |
import { normalizeURL } from "./lib/utils"; | ||
import { merge } from "./lib/merge"; | ||
|
||
export type DefaultGretchResponse = any; | ||
export type DefaultGretchError = any; | ||
|
||
export type MergeableObject = | ||
| { | ||
[k: string]: MergeableObject; | ||
} | ||
| Partial<GretchOptions> | ||
| any[]; | ||
|
||
export type GretchResponse<T = DefaultGretchResponse, A = DefaultGretchError> = | ||
| { | ||
|
@@ -47,13 +47,13 @@ | |
|
||
export type GretchOptions = { | ||
baseURL?: string; | ||
json?: { [key: string]: any }; | ||
retry?: RetryOptions | boolean; | ||
timeout?: number; | ||
onException?: (e: Error) => void; | ||
hooks?: GretchHooks; | ||
headers?: { [key: string]: any } & RequestInit["headers"]; | ||
[key: string]: any; | ||
} & RequestInit; | ||
|
||
export type GretchInstance<T, A> = { | ||
|
@@ -84,7 +84,7 @@ | |
...(rest as RequestInit), | ||
}; | ||
const controller = | ||
typeof AbortController !== "undefined" ? new AbortController() : null; | ||
typeof AbortController !== "undefined" ? new AbortController() : undefined; | ||
|
||
if (controller) { | ||
options.signal = controller.signal; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just flattening an array and iterating over it |
||
|
||
const fetcher = () => | ||
timeout | ||
|
@@ -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; | ||
} | ||
|
||
const res: GretchResponse<T, A> = { | ||
|
@@ -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; | ||
}; | ||
|
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. User options use |
||
}; | ||
|
||
export const defaultRetryOptions: RetryOptions = { | ||
|
There was a problem hiding this comment.
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 potentiallynull