Skip to content

Commit 624a335

Browse files
committed
improve Path param construction
1 parent 09c2ee5 commit 624a335

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

packages/openapi-react-query/src/index.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
useQuery,
1212
useSuspenseQuery,
1313
} from "@tanstack/react-query";
14-
import type { ClientMethod, FetchResponse, MaybeOptionalInit, Client as FetchClient, ClientPathsWithMethod } from "openapi-fetch";
14+
import type { ClientMethod, FetchResponse, MaybeOptionalInit, Client as FetchClient } from "openapi-fetch";
1515
import type { HttpMethod, MediaType, PathsWithMethod, RequiredKeysOf } from "openapi-typescript-helpers";
1616

1717
type InitWithUnknowns<Init> = Init & { [key: string]: unknown };
@@ -96,12 +96,13 @@ export interface OpenapiQueryClient<Paths extends {}, Media extends MediaType =
9696
export type MethodResponse<
9797
CreatedClient extends OpenapiQueryClient<any, any>,
9898
Method extends HttpMethod,
99-
Path extends ClientPathsWithMethod<FetchClient<any, any>, Method>,
100-
Options = {}
101-
> =
102-
CreatedClient extends OpenapiQueryClient<infer Paths extends { [key: string]: any }, infer Media extends MediaType>
103-
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]>
104-
: never
99+
Path extends CreatedClient extends OpenapiQueryClient<infer Paths, infer _Media>
100+
? PathsWithMethod<Paths, Method>
101+
: never,
102+
Options = object,
103+
> = CreatedClient extends OpenapiQueryClient<infer Paths extends { [key: string]: any }, infer Media extends MediaType>
104+
? NonNullable<FetchResponse<Paths[Path][Method], Options, Media>["data"]>
105+
: never;
105106

106107
// TODO: Add the ability to bring queryClient as argument
107108
export default function createClient<Paths extends {}, Media extends MediaType = MediaType>(
@@ -151,4 +152,3 @@ export default function createClient<Paths extends {}, Media extends MediaType =
151152
),
152153
};
153154
}
154-

packages/openapi-react-query/test/index.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ describe("client", () => {
212212

213213
const { data, error } = result.current;
214214

215-
expectTypeOf(data).toEqualTypeOf<MethodResponse<typeof client, "get", "/string-array"> | undefined>();
215+
expectTypeOf(data).toEqualTypeOf<MethodResponse<typeof client, "get", "/string-array"> | undefined>();
216216
expectTypeOf(data).toEqualTypeOf<string[] | undefined>();
217217
expectTypeOf(error).toEqualTypeOf<{ code: number; message: string } | null>();
218218
});

0 commit comments

Comments
 (0)