Skip to content

Commit

Permalink
Merge branch 'v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 20, 2024
2 parents 77e4b5a + f76d21b commit 9a71720
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/types/fetch/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ export interface $Fetch<
>(
request: R,
opts?: O
): Promise<TypedInternalResponse<R, T, ExtractedRouteMethod<R, O>>>;
): Promise<
TypedInternalResponse<
R,
T,
NitroFetchOptions<R> extends O ? "get" : ExtractedRouteMethod<R, O>
>
>;
raw<
T = DefaultT,
R extends NitroFetchRequest = DefaultR,
Expand All @@ -87,7 +93,13 @@ export interface $Fetch<
request: R,
opts?: O
): Promise<
FetchResponse<TypedInternalResponse<R, T, ExtractedRouteMethod<R, O>>>
FetchResponse<
TypedInternalResponse<
R,
T,
NitroFetchOptions<R> extends O ? "get" : ExtractedRouteMethod<R, O>
>
>
>;
create<T = DefaultT, R extends NitroFetchRequest = DefaultR>(
defaults: FetchOptions
Expand Down
7 changes: 7 additions & 0 deletions test/fixture/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ describe("API routes", () => {
});

it("generates the correct type depending on the method used", () => {
expectTypeOf($fetch("/api/methods")).toEqualTypeOf<Promise<"Index get">>();
expectTypeOf($fetch("/api/methods", {})).toEqualTypeOf<
Promise<"Index get">
>();
expectTypeOf($fetch("/api/methods", { query: {} })).toEqualTypeOf<
Promise<"Index get">
>();
expectTypeOf($fetch("/api/methods", { method: "get" })).toEqualTypeOf<
Promise<"Index get">
>();
Expand Down

0 comments on commit 9a71720

Please sign in to comment.