diff --git a/src/types/fetch.ts b/src/types/fetch.ts index b22a34a8f7..fa2df9f2e2 100644 --- a/src/types/fetch.ts +++ b/src/types/fetch.ts @@ -51,7 +51,7 @@ export type AvailableRouterMethod = // This overrides the default, which is only narrowed to a string. export interface NitroFetchOptions extends FetchOptions { - method?: AvailableRouterMethod; + method?: Uppercase> | AvailableRouterMethod; } // Extract the route method from options which might be undefined or without a method parameter. @@ -60,8 +60,8 @@ export type ExtractedRouteMethod< O extends NitroFetchOptions > = O extends undefined ? "get" - : O["method"] extends RouterMethod - ? O["method"] + : Lowercase extends RouterMethod + ? Lowercase : "get"; export interface $Fetch< diff --git a/test/fixture/types.ts b/test/fixture/types.ts index 3a35575ad6..1b2c53d184 100644 --- a/test/fixture/types.ts +++ b/test/fixture/types.ts @@ -182,13 +182,13 @@ describe("API routes", () => { Promise<"Index post"> >(); expectTypeOf( - $fetch("/api/methods/default", { method: "get" }) + $fetch("/api/methods/default", { method: "GET" }) ).toMatchTypeOf>(); expectTypeOf( - $fetch("/api/methods/default", { method: "put" }) + $fetch("/api/methods/default", { method: "PUT" }) ).toMatchTypeOf>(); expectTypeOf( - $fetch("/api/methods/default", { method: "post" }) + $fetch("/api/methods/default", { method: "POST" }) ).toMatchTypeOf>(); }); });