Skip to content
This repository was archived by the owner on May 22, 2023. It is now read-only.

Commit 3c7ce4b

Browse files
committed
optional 2nd parameter
1 parent adb65fa commit 3c7ce4b

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/index.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -140,36 +140,36 @@ export default function createClient<T>(defaultOptions?: ClientOptions) {
140140

141141
return {
142142
/** Call a GET endpoint */
143-
async get<U extends PathsWith<'get'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
144-
return coreFetch(url, { ...options, method: 'GET' });
143+
async get<U extends PathsWith<'get'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
144+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'GET' });
145145
},
146146
/** Call a PUT endpoint */
147-
async put<U extends PathsWith<'put'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
148-
return coreFetch(url, { ...options, method: 'PUT' });
147+
async put<U extends PathsWith<'put'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
148+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'PUT' });
149149
},
150150
/** Call a POST endpoint */
151-
async post<U extends PathsWith<'post'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
152-
return coreFetch(url, { ...options, method: 'POST' });
151+
async post<U extends PathsWith<'post'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
152+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'POST' });
153153
},
154154
/** Call a DELETE endpoint */
155-
async del<U extends PathsWith<'delete'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
156-
return coreFetch(url, { ...options, method: 'DELETE' });
155+
async del<U extends PathsWith<'delete'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
156+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'DELETE' });
157157
},
158158
/** Call a OPTIONS endpoint */
159-
async options<U extends PathsWith<'options'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
160-
return coreFetch(url, { ...options, method: 'OPTIONS' });
159+
async options<U extends PathsWith<'options'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
160+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'OPTIONS' });
161161
},
162162
/** Call a HEAD endpoint */
163-
async head<U extends PathsWith<'head'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
164-
return coreFetch(url, { ...options, method: 'HEAD' });
163+
async head<U extends PathsWith<'head'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
164+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'HEAD' });
165165
},
166166
/** Call a PATCH endpoint */
167-
async patch<U extends PathsWith<'patch'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
168-
return coreFetch(url, { ...options, method: 'PATCH' });
167+
async patch<U extends PathsWith<'patch'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
168+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'PATCH' });
169169
},
170170
/** Call a TRACE endpoint */
171-
async trace<U extends PathsWith<'trace'>, M extends keyof T[U]>(url: U, options: FetchOptions<U, M>) {
172-
return coreFetch(url, { ...options, method: 'TRACE' });
171+
async trace<U extends PathsWith<'trace'>, M extends keyof T[U]>(url: U, options?: FetchOptions<U, M>) {
172+
return coreFetch(url, { ...(options ?? ({} as FetchOptions<U, M>)), method: 'TRACE' });
173173
},
174174
};
175175
}

0 commit comments

Comments
 (0)