diff --git a/src/fetch.ts b/src/fetch.ts index 162ea45..5a6cd0e 100644 --- a/src/fetch.ts +++ b/src/fetch.ts @@ -49,7 +49,7 @@ export interface FetchEventSourceInit extends RequestInit { */ openWhenHidden?: boolean; - /** The Fetch function to use. Defaults to window.fetch */ + /** The Fetch function to use. Defaults to globalThis.fetch */ fetch?: typeof fetch; } @@ -84,10 +84,10 @@ export function fetchEventSource(input: RequestInfo, { } let retryInterval = DefaultRetryInterval; - let retryTimer = 0; + let retryTimer: number = 0; function dispose() { document.removeEventListener('visibilitychange', onVisibilityChange); - window.clearTimeout(retryTimer); + globalThis.clearTimeout(retryTimer); curRequestController.abort(); } @@ -97,7 +97,7 @@ export function fetchEventSource(input: RequestInfo, { resolve(); // don't waste time constructing/logging errors }); - const fetch = inputFetch ?? window.fetch; + const fetch = inputFetch ?? globalThis.fetch; const onopen = inputOnOpen ?? defaultOnOpen; async function create() { curRequestController = new AbortController(); @@ -131,8 +131,8 @@ export function fetchEventSource(input: RequestInfo, { try { // check if we need to retry: const interval: any = onerror?.(err) ?? retryInterval; - window.clearTimeout(retryTimer); - retryTimer = window.setTimeout(create, interval); + globalThis.clearTimeout(retryTimer); + retryTimer = globalThis.setTimeout(create, interval) as unknown as number; } catch (innerErr) { // we should not retry anymore: dispose();