Skip to content

Commit

Permalink
fix: accept both upper/lower-case methods (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Dec 14, 2022
1 parent 5730a7f commit cbcd068
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/types/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export type AvailableRouterMethod<R extends NitroFetchRequest> =
// This overrides the default, which is only narrowed to a string.
export interface NitroFetchOptions<R extends NitroFetchRequest>
extends FetchOptions {
method?: AvailableRouterMethod<R>;
method?: Uppercase<AvailableRouterMethod<R>> | AvailableRouterMethod<R>;
}

// Extract the route method from options which might be undefined or without a method parameter.
Expand All @@ -60,8 +60,8 @@ export type ExtractedRouteMethod<
O extends NitroFetchOptions<R>
> = O extends undefined
? "get"
: O["method"] extends RouterMethod
? O["method"]
: Lowercase<O["method"]> extends RouterMethod
? Lowercase<O["method"]>
: "get";

export interface $Fetch<
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ describe("API routes", () => {
Promise<"Index post">
>();
expectTypeOf(
$fetch("/api/methods/default", { method: "get" })
$fetch("/api/methods/default", { method: "GET" })
).toMatchTypeOf<Promise<"Default route">>();
expectTypeOf(
$fetch("/api/methods/default", { method: "put" })
$fetch("/api/methods/default", { method: "PUT" })
).toMatchTypeOf<Promise<"Default route">>();
expectTypeOf(
$fetch("/api/methods/default", { method: "post" })
$fetch("/api/methods/default", { method: "POST" })
).toMatchTypeOf<Promise<"Default override">>();
});
});

0 comments on commit cbcd068

Please sign in to comment.