update examples and add documentation

This commit is contained in:
zekro committed 2026-07-17 11:30:08 +02:00
1 parent 9e4e019660
commit e42d897d41
7 files changed
+34 -21

No files matched your search

+7
View File
@@ -1,3 +1,9 @@
// This recursively matches path segments and parameters in segments which
// are surrounded by curly braces (i.e. `{foo}`) in these segments.
// The results are joined to a superset of objects with their params
// via the `&`.
// In example, the path /{foo}/{bar} results in the type
// `{ foo: string } & { bar: string }`
type ParseUrlParamsRaw<Url> = Url extends `${infer Start}/${infer Rest}`
? ParseUrlParamsRaw<Start> & ParseUrlParamsRaw<Rest>
: Url extends `{${infer Param}}`
@@ -20,4 +26,5 @@ function navigate<P extends string>(path: P, params: ParseUrlParams<P>) {
function main() {
navigate("/hello", {});
navigate("/hello/{name}", { name: "foo" });
navigate("/book/{author}/{id}", { author: "foo", id: "bar" });
}