Skip to content

feat(next-typed-href): add branded option to return TypedHref from $href()#83

Merged
amotarao merged 5 commits into
mainfrom
feature/pc-121
May 27, 2026
Merged

feat(next-typed-href): add branded option to return TypedHref from $href()#83
amotarao merged 5 commits into
mainfrom
feature/pc-121

Conversation

@amotarao
Copy link
Copy Markdown
Member

Summary

  • TypedHref branded type (string & { readonly __brand: "TypedHref" }) を common/types.ts に追加
  • defineTypedHref.routes<R, M>({ branded: true })$href() の戻り値が TypedHref になるよう対応
  • defineTypedHrefWithNuqs.routes<R, M>().withOptions({ branded: true }).nuqs({}) でも同様に対応
  • デフォルト(オプションなし)は string のまま — 後方互換を保持
  • TypedHrefstring のサブタイプなので既存コードへの影響なし

Test plan

  • 型チェック: pnpm --filter @plainbrew/next-typed-href type-check
  • テスト: pnpm --filter @plainbrew/next-typed-href test:run (55テスト通過)
  • branded: true 時に $href()TypedHref を返すことを型レベルで検証
  • branded なしで既存コードが壊れないことを確認

Closes PC-121

🤖 Generated with Claude Code

amotarao and others added 5 commits May 26, 2026 15:23
…ref()

Introduces TypedHref branded type and branded option to both defineTypedHref and defineTypedHrefWithNuqs. When { branded: true } is passed, $href() returns TypedHref instead of string, enabling type-level distinction from plain strings while preserving backward compatibility.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…re branded option API

- Translate Japanese inline comments in JSDoc to English
- Change branded option from routes() argument to withOptions() chain for both
  defineTypedHref and defineTypedHrefWithNuqs, matching the existing withOptions pattern
- Narrow branded type to `true` only to preserve literal type inference
- Add withOptions() chain to defineTypedHref for consistency with defineTypedHrefWithNuqs

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

Changes branded option type from `true` to `boolean` and adds `const` modifier
to withOptions generic so TypeScript preserves the literal type of the argument,
ensuring HrefReturn resolves to TypedHref when branded: true is passed.

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

- Fix setup examples to use defineTypedHref.routes<>() and
  defineTypedHrefWithNuqs.routes<>().nuqs({}) (old API was outdated)
- Add TypedHref section explaining branded return type and withOptions usage
- Add withOptions section covering requiredSearchParams and branded options

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@amotarao amotarao requested a review from akameco May 26, 2026 07:13
Copy link
Copy Markdown
Contributor

@akameco akameco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

テスト確認OK。LGTM〜

imo: src/index.tscreateWithTypedHrefRoutes / WithTypedHrefRoutes と、src/nuqs.tscreateWithRoutes / WithRoutes で、ほぼ同じ役割の関数・型なのに命名が分かれているのがちょっと気になる。
両方ともファイル内ローカル(export していない)ため名前空間の衝突は無いので合わせてしまっていいと思う。

@amotarao
Copy link
Copy Markdown
Member Author

Linear issue 起票したのであとまわし: https://linear.app/plainbrew/issue/PC-122

@amotarao amotarao merged commit f999b64 into main May 27, 2026
1 check passed
@amotarao amotarao deleted the feature/pc-121 branch May 27, 2026 01:20
@github-actions github-actions Bot mentioned this pull request May 27, 2026
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.

2 participants