From 27ce229595c1ed238fd317f704f862adec9f8793 Mon Sep 17 00:00:00 2001 From: Amon Sawamura Date: Wed, 22 Apr 2026 18:36:08 +0900 Subject: [PATCH 1/2] docs: document curried pattern and named factory usage in defineTypedHrefWithNuqs Co-Authored-By: Claude Sonnet 4.6 --- packages/next-typed-href/src/nuqs.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/next-typed-href/src/nuqs.ts b/packages/next-typed-href/src/nuqs.ts index 4a6fb50..87d4eac 100644 --- a/packages/next-typed-href/src/nuqs.ts +++ b/packages/next-typed-href/src/nuqs.ts @@ -19,8 +19,15 @@ type ParserValues> = { * Routes that have nuqs parsers defined accept typed searchParams values. * Routes without parsers fall back to standard URLSearchParams input. * + * The function is curried — call it once with explicit type parameters to get + * a route-specific factory, then call that factory with your parsers map. + * TypeScript cannot infer the third type parameter alongside explicit ones + * (microsoft/TypeScript#26242), so the two-step form is required. + * * @example - * const { $href } = defineTypedHrefWithNuqs()({ + * // Recommended: store the factory and call it once + * const withNuqs = defineTypedHrefWithNuqs(); + * const { $href } = withNuqs({ * "/search": { q: parseAsString, page: parseAsInteger }, * }); * From 6571f691981bbfc7be9d3977c69df7d4bc5db481 Mon Sep 17 00:00:00 2001 From: Amon Sawamura Date: Wed, 22 Apr 2026 18:56:01 +0900 Subject: [PATCH 2/2] docs: update README and add changeset for named factory pattern Co-Authored-By: Claude Sonnet 4.6 --- .changeset/teal-cups-swim.md | 5 +++++ packages/next-typed-href/README.md | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 .changeset/teal-cups-swim.md diff --git a/.changeset/teal-cups-swim.md b/.changeset/teal-cups-swim.md new file mode 100644 index 0000000..66a54bc --- /dev/null +++ b/.changeset/teal-cups-swim.md @@ -0,0 +1,5 @@ +--- +"@plainbrew/next-typed-href": patch +--- + +docs: document named factory pattern and reason for curried design in defineTypedHrefWithNuqs diff --git a/packages/next-typed-href/README.md b/packages/next-typed-href/README.md index aa80536..e97ef3b 100644 --- a/packages/next-typed-href/README.md +++ b/packages/next-typed-href/README.md @@ -81,7 +81,9 @@ import type { AppRoutes, ParamsOf } from "@/../.next/types/routes"; type AppRouteParamsMap = { [Route in AppRoutes]: ParamsOf }; -export const { $href } = defineTypedHrefWithNuqs()({ +const withNuqs = defineTypedHrefWithNuqs(); + +export const { $href } = withNuqs({ "/search": { q: parseAsString, page: parseAsInteger, @@ -116,7 +118,9 @@ $href({ route: "/users/[id]", routeParams: { id: "42" }, searchParams: { tab: "p Parsers wrapped with `.withDefault()` make the type non-nullable and omit the key from the URL when the value equals the default: ```ts -export const { $href } = defineTypedHrefWithNuqs()({ +const withNuqs = defineTypedHrefWithNuqs(); + +export const { $href } = withNuqs({ "/search": { q: parseAsString.withDefault(""), page: parseAsInteger.withDefault(1),