Skip to content

Commit 585b1a6

Browse files
authored
Fix post() and options() types (#1104)
1 parent 7e4164c commit 585b1a6

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

packages/openapi-fetch/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# openapi-fetch
22

3+
## 0.1.2
4+
5+
### Patch Changes
6+
7+
- e730cd8: Fix post() and options() types
8+
39
## 0.1.1
410

511
### Patch Changes

packages/openapi-fetch/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ export type RequestBodyObj<O> = O extends { requestBody: any } ? O["requestBody"
4040
export type RequestBodyContent<O> = undefined extends RequestBodyObj<O> ? FilterKeys<NonNullable<RequestBodyObj<O>>, "content"> | undefined : FilterKeys<RequestBodyObj<O>, "content">;
4141
export type RequestBodyJSON<O> = FilterKeys<RequestBodyContent<O>, JSONLike> extends never ? FilterKeys<NonNullable<RequestBodyContent<O>>, JSONLike> | undefined : FilterKeys<RequestBodyContent<O>, JSONLike>;
4242
export type RequestBody<O> = undefined extends RequestBodyJSON<O> ? { body?: RequestBodyJSON<O> } : { body: RequestBodyJSON<O> };
43-
export type QuerySerializer<O> = { querySerializer?: (query: O extends { parameters: { query: any } } ? O["parameters"]["query"] : Record<string, unknown>) => string };
44-
export type FetchOptions<T> = Params<T> & RequestBody<T> & Omit<RequestInit, "body"> & QuerySerializer<T>;
43+
export type QuerySerializer<O> = (query: O extends { parameters: { query: any } } ? O["parameters"]["query"] : Record<string, unknown>) => string;
44+
export type FetchOptions<T> = Params<T> & RequestBody<T> & Omit<RequestInit, "body"> & { querySerializer?: QuerySerializer<T> };
4545
export type Success<O> = FilterKeys<FilterKeys<O, OkStatus>, "content">;
4646
export type Error<O> = FilterKeys<FilterKeys<O, ErrorStatus>, "content">;
4747
export type FetchResponse<T> =
@@ -99,15 +99,15 @@ export default function createClient<Paths extends {}>(options?: ClientOptions)
9999
},
100100
/** Call a POST endpoint */
101101
async post<P extends PathsWith<Paths, "post">>(url: P, init: FetchOptions<FilterKeys<Paths[P], "post">>) {
102-
return coreFetch<P, "put">(url, { ...init, method: "POST" } as any);
102+
return coreFetch<P, "post">(url, { ...init, method: "POST" } as any);
103103
},
104104
/** Call a DELETE endpoint */
105105
async del<P extends PathsWith<Paths, "delete">>(url: P, init: FetchOptions<FilterKeys<Paths[P], "delete">>) {
106106
return coreFetch<P, "delete">(url, { ...init, method: "DELETE" } as any);
107107
},
108108
/** Call a OPTIONS endpoint */
109109
async options<P extends PathsWith<Paths, "options">>(url: P, init: FetchOptions<FilterKeys<Paths[P], "options">>) {
110-
return coreFetch<P, "delete">(url, { ...init, method: "OPTIONS" } as any);
110+
return coreFetch<P, "options">(url, { ...init, method: "OPTIONS" } as any);
111111
},
112112
/** Call a HEAD endpoint */
113113
async head<P extends PathsWith<Paths, "head">>(url: P, init: FetchOptions<FilterKeys<Paths[P], "head">>) {

0 commit comments

Comments
 (0)