Skip to content

feat(next-typed-href): add nonNullableSearchParams option#59

Draft
amotarao wants to merge 3 commits into
mainfrom
feat/nuqs-strict-search-params
Draft

feat(next-typed-href): add nonNullableSearchParams option#59
amotarao wants to merge 3 commits into
mainfrom
feat/nuqs-strict-search-params

Conversation

@amotarao
Copy link
Copy Markdown
Member

@amotarao amotarao commented Apr 28, 2026

概要

defineTypedHrefWithNuqsnonNullableSearchParams オプションを追加する。
requiredSearchParams とは独立した別軸のオプションで、組み合わせて使用可能。

オプション対比

オプション 効果
デフォルト searchParams は optional、null も許容
requiredSearchParams: true nuqs parsers があるルートで searchParams が必須、withDefault なしフィールドが required(null は許容)
nonNullableSearchParams: true すべてのフィールドで null を型エラーにする(searchParams 自体は optional のまま)
両方 true searchParams が必須、withDefault なしフィールドが required かつ non-nullable

型の変化

| モード                                          | withDefault なし        | withDefault あり |
|-------------------------------------------------|------------------------|-----------------|
| デフォルト                                       | q?: string \| null     | q?: string      |
| requiredSearchParams: true                      | q: string \| null      | q?: string      |
| nonNullableSearchParams: true                   | q?: string             | q?: string      |
| requiredSearchParams: true + nonNullableSearchParams: true | q: string | q?: string      |

使用例

// nonNullableSearchParams のみ — searchParams は optional、null は型エラー
const { $href } = defineTypedHrefWithNuqs<Routes, RouteParamsMap>()({
  nonNullableSearchParams: true,
})({ "/search": { q: parseAsString, page: parseAsInteger.withDefault(1) } });

$href({ route: "/search" })                                  // OK
$href({ route: "/search", searchParams: { q: "hello" } })  // OK
$href({ route: "/search", searchParams: { q: null } })      // Type error

// 両方 — searchParams が必須、null も型エラー
const { $href } = defineTypedHrefWithNuqs<Routes, RouteParamsMap>()({
  requiredSearchParams: true,
  nonNullableSearchParams: true,
})({ "/search": { q: parseAsString, page: parseAsInteger.withDefault(1) } });

$href({ route: "/search" })                                  // Type error: searchParams is required
$href({ route: "/search", searchParams: { q: "hello" } })  // OK
$href({ route: "/search", searchParams: { q: null } })      // Type error: null not allowed

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 18b0f9e3-33a4-4a23-8e42-50ccfa4d6cbc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/nuqs-strict-search-params

Comment @coderabbitai help to get the list of available commands and usage tips.

amotarao and others added 2 commits April 28, 2026 18:21
…low null)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…uiredSearchParams

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@amotarao amotarao changed the title feat(next-typed-href): add strict mode (no null) feat(next-typed-href): add nonNullableSearchParams option Apr 28, 2026
Base automatically changed from feat/nuqs-require-search-params to main April 30, 2026 03:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant