From cbcd0681d37839f93fc7f3f106d34e3f01d2ac84 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 14 Dec 2022 13:34:51 +0000 Subject: [PATCH] fix: accept both upper/lower-case methods (#752) --- src/types/fetch.ts | 6 +++--- test/fixture/types.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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>(); }); });