Skip to content

Commit 963b95d

Browse files
authored
make Record<string, never> payloads optional
1 parent a723f81 commit 963b95d

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/index.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,16 @@ export type Fetch = (
9191
export type _TypedFetch<OP> = (
9292
arg: OpArgType<OP>,
9393
init?: RequestInit,
94-
) => Promise<ApiResponse<OpReturnType<OP>>>
95-
96-
export type TypedFetch<OP> = _TypedFetch<OP> & {
94+
) => Promise<ApiResponse<OpReturnType<OP>>>
95+
96+
export type _TypedFetchOptional<OP> =
97+
OpArgType<OP> extends Record<PropertyKey, never> ?
98+
(
99+
arg?: OpArgType<OP>,
100+
init?: RequestInit
101+
) => Promise<ApiResponse<OpReturnType<OP>>> : _TypedFetch<OP>
102+
103+
export type TypedFetch<OP> = _TypedFetchOptional<OP> & {
97104
Error: new (error: ApiError) => ApiError & {
98105
getActualType: () => OpErrorType<OP>
99106
}
@@ -347,7 +354,7 @@ async function fetchUrl<R>(request: Request) {
347354
})) as ApiResponse<R>
348355
}
349356

350-
function createFetch<OP>(fetch: _TypedFetch<OP>): TypedFetch<OP> {
357+
function createFetch<OP>(fetch: _TypedFetchOptional<OP>): TypedFetch<OP> {
351358
const fun = async (payload: OpArgType<OP>, init?: RequestInit) => {
352359
try {
353360
return await fetch(payload, init)
@@ -398,7 +405,7 @@ function fetcher<Paths>() {
398405
path: path as string,
399406
method: method as Method,
400407
queryParams: Object.keys(queryParams || {}),
401-
payload,
408+
payload: payload || {},
402409
init: mergeRequestInit(defaultInit, init),
403410
fetch,
404411
}),

0 commit comments

Comments
 (0)