Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: accept both upper/lower-case methods #752

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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">>();
});
});