diff --git a/examples/express/fetch.ts b/examples/express/fetch.ts index feae716..006c42e 100644 --- a/examples/express/fetch.ts +++ b/examples/express/fetch.ts @@ -31,7 +31,10 @@ const main = async () => { unreachable(res); } } - + { + // case-insensitive method example + await fetchT(`${origin}/users`, { method: "GET" }); + } { // query parameter example // TODO: Add common information for query parameter diff --git a/src/common/spec.ts b/src/common/spec.ts index 3ce074e..7c512b7 100644 --- a/src/common/spec.ts +++ b/src/common/spec.ts @@ -11,6 +11,7 @@ export const Method = [ "head", ] as const; export type Method = (typeof Method)[number]; +export type CaseInsensitiveMethod = Method | Uppercase; export type ApiEndpoint = Partial< Record>> diff --git a/src/fetch/index.ts b/src/fetch/index.ts index 711ffd1..5d1f5ed 100644 --- a/src/fetch/index.ts +++ b/src/fetch/index.ts @@ -1,6 +1,7 @@ import { ApiBodySchema, ApiEndpoints, + CaseInsensitiveMethod, MergeApiResponses, Method, NormalizePath, @@ -15,11 +16,11 @@ import { import { TypedString } from "../json"; export interface RequestInitT< - M extends Method, + InputMethod extends CaseInsensitiveMethod, // eslint-disable-next-line @typescript-eslint/no-explicit-any Body extends Record | undefined, > extends RequestInit { - method?: M; + method?: InputMethod; body?: TypedString; } @@ -36,10 +37,11 @@ type FetchT = < "" >, CandidatePaths extends MatchedPatterns, - M extends Method = "get", + InputMethod extends CaseInsensitiveMethod = "get", + M extends Method = Lowercase, >( input: Input, - init?: RequestInitT>, + init?: RequestInitT>, // FIXME: NonNullable ) => Promise["res"]>>;