diff --git a/src/types/fetch/fetch.ts b/src/types/fetch/fetch.ts index ca5aabf1e4..21c8c8c377 100644 --- a/src/types/fetch/fetch.ts +++ b/src/types/fetch/fetch.ts @@ -78,7 +78,13 @@ export interface $Fetch< >( request: R, opts?: O - ): Promise>>; + ): Promise< + TypedInternalResponse< + R, + T, + NitroFetchOptions extends O ? "get" : ExtractedRouteMethod + > + >; raw< T = DefaultT, R extends NitroFetchRequest = DefaultR, @@ -87,7 +93,13 @@ export interface $Fetch< request: R, opts?: O ): Promise< - FetchResponse>> + FetchResponse< + TypedInternalResponse< + R, + T, + NitroFetchOptions extends O ? "get" : ExtractedRouteMethod + > + > >; create( defaults: FetchOptions diff --git a/test/fixture/types.ts b/test/fixture/types.ts index e7a82c3fae..404749543d 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -183,6 +183,13 @@ describe("API routes", () => { }); it("generates the correct type depending on the method used", () => { + expectTypeOf($fetch("/api/methods")).toEqualTypeOf>(); + 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"> >();