Skip to content

Commit 88169fe

Browse files
authored
Normalize InputPath (#48)
* Normalize InputPath * Normalize InputPath
1 parent 207a542 commit 88169fe

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/fetch/index.t-test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,13 @@ import JSONT from "../json";
128128
headers: { Cookie: "a=b" },
129129
});
130130
})();
131+
132+
(async () => {
133+
// basePathの最後にも/があるのでhttps://example.com/api//usersとなってしまうが、ノーマライズされるので問題ない
134+
const basePath = "https://example.com/api/";
135+
const f = fetch as FetchT<typeof basePath, Spec>;
136+
await f(`${basePath}/users`, {
137+
headers: { Cookie: "a=b" },
138+
});
139+
})();
131140
}

src/fetch/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ type FetchT<UrlPrefix extends UrlPrefixPattern, E extends ApiEndpoints> = <
3636
Input extends
3737
| `${ToUrlParamPattern<UrlPrefix>}${ToUrlParamPattern<keyof E & string>}`
3838
| `${ToUrlParamPattern<UrlPrefix>}${ToUrlParamPattern<keyof E & string>}?${string}`,
39-
InputPath extends ParseURL<
40-
Replace<NormalizePath<Input>, NormalizePath<UrlPrefix>, "">
41-
>["path"],
39+
InputPath extends NormalizePath<
40+
ParseURL<Replace<Input, UrlPrefix, "">>["path"]
41+
>,
4242
CandidatePaths extends MatchedPatterns<InputPath, keyof E & string>,
4343
InputMethod extends CaseInsensitiveMethod = "get",
4444
M extends Method = Lowercase<InputMethod>,

0 commit comments

Comments
 (0)