Skip to content
This repository was archived by the owner on Oct 9, 2025. It is now read-only.

Commit f7c74a4

Browse files
committed
fix: illegal invocation
1 parent 6a3ea4f commit f7c74a4

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/helper.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import crossFetch from 'cross-fetch'
2+
3+
type Fetch = typeof fetch
4+
5+
export const resolveFetch = (customFetch?: Fetch): Fetch => {
6+
let _fetch: Fetch
7+
if (customFetch) {
8+
_fetch = customFetch
9+
} else if (typeof fetch === 'undefined') {
10+
_fetch = crossFetch as unknown as Fetch
11+
} else {
12+
_fetch = fetch
13+
}
14+
return (...args) => _fetch(...args)
15+
}

src/index.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import crossFetch from 'cross-fetch'
2-
import { Fetch, FunctionInvokeOptions, ResponseType } from './types'
1+
import { resolveFetch } from './helper'
2+
import { Fetch, FunctionInvokeOptions } from './types'
33

44
export class FunctionsClient {
55
protected url: string
@@ -10,13 +10,7 @@ export class FunctionsClient {
1010
this.url = url
1111
this.headers = headers
1212

13-
if (customFetch) {
14-
this.fetch = customFetch
15-
} else if (typeof fetch !== 'undefined') {
16-
this.fetch = fetch
17-
} else {
18-
this.fetch = crossFetch
19-
}
13+
this.fetch = resolveFetch(fetch)
2014
}
2115

2216
/**

0 commit comments

Comments
 (0)