Skip to content

Commit 645f436

Browse files
authored
fix types on passing request options (#1639)
* fix types on passing request options * add changeset
1 parent 627138c commit 645f436

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.changeset/orange-coins-pull.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"openapi-fetch": patch
3+
---
4+
5+
fix request option types don't showing optional props correctly

packages/openapi-fetch/src/index.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -158,16 +158,16 @@ type PathMethods = Partial<Record<HttpMethod, {}>>;
158158
export type MaybeOptionalInit<P extends PathMethods, M extends keyof P> = HasRequiredKeys<
159159
FetchOptions<FilterKeys<P, M>>
160160
> extends never
161-
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
162-
: [FetchOptions<FilterKeys<P, M>>];
161+
? FetchOptions<FilterKeys<P, M>> | undefined
162+
: FetchOptions<FilterKeys<P, M>>;
163163

164164
export type ClientMethod<Paths extends Record<string, PathMethods>, M extends HttpMethod, Media extends MediaType> = <
165165
P extends PathsWithMethod<Paths, M>,
166166
I extends MaybeOptionalInit<Paths[P], M>,
167167
>(
168168
url: P,
169-
...init: I
170-
) => Promise<FetchResponse<Paths[P][M], I[0], Media>>;
169+
...init: HasRequiredKeys<I> extends never ? [I?] : [I]
170+
) => Promise<FetchResponse<Paths[P][M], I, Media>>;
171171

172172
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>(
173173
clientOptions?: ClientOptions,

0 commit comments

Comments
 (0)