Skip to content

Fix path method object types #1585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/funny-keys-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-fetch": patch
---

Update types for path-methods object
9 changes: 4 additions & 5 deletions packages/openapi-fetch/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,16 @@ export interface Middleware {
onResponse?: typeof onResponse;
}

type PathMethods = Partial<Record<HttpMethod, {}>>;

/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
export type MaybeOptionalInit<
P extends Record<HttpMethod, {}>,
M extends keyof P,
> =
export type MaybeOptionalInit<P extends PathMethods, M extends keyof P> =
HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
: [FetchOptions<FilterKeys<P, M>>];

export type ClientMethod<
Paths extends Record<string, Record<HttpMethod, {}>>,
Paths extends Record<string, PathMethods>,
M extends HttpMethod,
> = <
P extends PathsWithMethod<Paths, M>,
Expand Down